From: Vivek Subramanian on 27 Jul 2010 12:50 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? In other words, I would like to do something like this: features = (extfeature(signal))([5, 17, 38]); rather than features = extfeature(signal); features = features([5, 17, 38]); Thank you!! Vivek
From: us on 27 Jul 2010 13:05 "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? > > In other words, I would like to do something like this: > > features = (extfeature(signal))([5, 17, 38]); > > rather than > > features = extfeature(signal); > features = features([5, 17, 38]); > > Thank you!! > Vivek simply said: ML does NOT implement this syntax... see the very many similar CSSM threads re this particular issue... us
From: Walter Roberson on 27 Jul 2010 14:17 Vivek Subramanian wrote: > 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? getNth = @(v,n) v(n); getNth( extfeature(...), [5, 17, 38]); This satisfies the letter of your requirement that you do not have to store the value in a variable, but violates the spirit of your requirement in that the value still gets associated with a variable which is the dummy parameter to the anonymous function.
From: Vivek Subramanian on 29 Jul 2010 07:30 Thank you both for your responses! Walter Roberson <roberson(a)hushmail.com> wrote in message <i2n83c$dcq$1(a)canopus.cc.umanitoba.ca>... > Vivek Subramanian wrote: > > > 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? > > getNth = @(v,n) v(n); > > getNth( extfeature(...), [5, 17, 38]); > > > This satisfies the letter of your requirement that you do not have to store > the value in a variable, but violates the spirit of your requirement in that > the value still gets associated with a variable which is the dummy parameter > to the anonymous function.
From: Matt J on 29 Jul 2010 10:47 "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])
|
Next
|
Last
Pages: 1 2 Prev: GUI Error When Running Next: Placing a multidimensional array in a 2D array |