Prev: How To Write Modified Fibonacci Sequence
Next: How to enlarge the Memory available for all arrays
From: Adam Hartshorne on 2 Mar 2010 22:24 Say I have a function X, that takes an input Y and returns an array / matrix. Now I really only want the nth element of the array / matrix. Obviously I could do, temp = X(Y) wantedVar = temp(n) ; Is there an easy way of doing both operations in a single line of code, something along the lines of wantedVar = (X(Y))(n) Any help much appreciated, Adam
From: Doug Schwarz on 2 Mar 2010 22:58 In article <hmkkoo$phj$1(a)fred.mathworks.com>, "Adam Hartshorne" <adam.hartshorne(a)gmail.com> wrote: > Say I have a function X, that takes an input Y and returns an array / matrix. > Now I really only want the nth element of the array / matrix. > > Obviously I could do, > > temp = X(Y) > wantedVar = temp(n) ; > > Is there an easy way of doing both operations in a single line of code, > something along the lines of > > wantedVar = (X(Y))(n) > > Any help much appreciated, > > Adam It's a FAQ and the answer is no. -- Doug Schwarz dmschwarz&ieee,org Make obvious changes to get real email address.
From: Matt J on 5 Mar 2010 12:49 "Adam Hartshorne" <adam.hartshorne(a)gmail.com> wrote in message <hmkkoo$phj$1(a)fred.mathworks.com>... > Say I have a function X, that takes an input Y and returns an array / matrix. Now I really only want the nth element of the array / matrix. > > Obviously I could do, > > temp = X(Y) > wantedVar = temp(n) ; > > Is there an easy way of doing both operations in a single line of code, something along the lines of > > wantedVar = (X(Y))(n) ===================== If you're only looking for the benefits of simplified syntax, this will let you do something very similar: http://www.mathworks.com/matlabcentral/fileexchange/26570-direct-indexing-of-function-calls-oop-exercise Note that if your function X is not a native MATLAB function, you can add a handle to it in the LibraryStruct.mat structure, S. You could also make S the constant property of some class so that it is globally accessible.
|
Pages: 1 Prev: How To Write Modified Fibonacci Sequence Next: How to enlarge the Memory available for all arrays |