From: Andy on 29 Jul 2010 11:11 "Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message <i2s49o$pk6$1(a)fred.mathworks.com>... > "Vivek Subramanian" <vas11(a)duke.edu> wrote in message <i2n2oe$3eo$1(a)fred.mathworks.com>... > > Hi everyone, > > > > I am wondering how one can index a matrix that is returned by a function without first storing it in a variable. For instance, I am using a function called extfeature.m which returns a 1 by 45 matrix containing the values of 45 features I have extracted from an EEG signal. I would like to store only the 5th, 17th, and 38th feature values. Is there a way I can do this in one line instead of having to first initialize a variable to store all 45 values and then re-initializing it to store only those values? > ========== > > Yes, you can use the following FEX tool > > http://www.mathworks.com/matlabcentral/fileexchange/26570-direct-indexing-of-function-calls-oop-exercise > > It would allow you to do something like this > > %Get an indexable function handle to extfeature > >> h=IndexableFunction(extfeature); > > %Call extfeature with arg1,arg2,etc... and index result at 5th,17th,18th elements > >> result=h{arg1,arg2,...}([5,17,38]) Correct me if I'm wrong, but, internally, doesn't that just calculate the entire output of h and then index into it? It saves typing (if you make frequent use of this functionality), but it doesn't, for example, save the memory used to store the entire output of h at some point.
From: Matt J on 29 Jul 2010 12:32 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i2s5ma$t1s$1(a)fred.mathworks.com>... > > Correct me if I'm wrong, but, internally, doesn't that just calculate the entire output of h and then index into it? It saves typing (if you make frequent use of this functionality), but it doesn't, for example, save the memory used to store the entire output of h at some point. ================== You're not wrong, but my understanding of the OP was that he was just trying to save typing. As explained at the FEX link, it would never be possible to approach this kind of post-indexing syntax in a memory-conserving way. That's because certain functions/algorithms like fft() are inherently incapable of generating the components of their vector-valued output individually.
First
|
Prev
|
Pages: 1 2 Prev: GUI Error When Running Next: Placing a multidimensional array in a 2D array |