From: Anthony Hopf on 14 May 2010 10:12 Hi everyone, I have a little issue. Have a matrix of index values IND that I would like to use to index values in another matrix A... thing is IND has a bunch of NaN in it and I get a the error: "??? Subscript indices must either be real positive integers or logicals." when I do TempA = A(IND); This is due to the NaNs in IND. I found the following link which specifies a class that can be indexed my NaNs, but the problem is it will also return NaN values where NaN was used to index: A=NanIndexable([10 20 30]); IND = [2 nan 3]; >> A(IND) %The result you wanted ans = 20 NaN 30 I want it to return nothing where IND is NaN... any ideas? reference to the link i found on matlab central http://www.mathworks.se/matlabcentral/newsreader/view_thread/265702 Thank you, Tony
From: Steven Lord on 14 May 2010 10:23 "Anthony Hopf" <anthony.hopf(a)gmail.com> wrote in message news:hsjlnl$o8g$1(a)fred.mathworks.com... > Hi everyone, > > I have a little issue. Have a matrix of index values IND that I would > like to use to index values in another matrix A... thing is IND has a > bunch of NaN in it and I get a the error: > "??? Subscript indices must either be real positive integers or logicals." Then pull out the NaNs. A(IND(~isnan(IND))) -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
From: Jan Simon on 14 May 2010 10:27 Dear Anthony! > I have a little issue. Have a matrix of index values IND that I would like to use to index values in another matrix A... thing is IND has a bunch of NaN in it and I get a the error: > "??? Subscript indices must either be real positive integers or logicals." > > when I do > TempA = A(IND); TempA = A(IND(isfinite(IND)) or TempA = A(IND(~isnan(IND)) Jan
From: Anthony Hopf on 14 May 2010 14:05 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hsjmkb$pkq$1(a)fred.mathworks.com>... > Dear Anthony! > > > I have a little issue. Have a matrix of index values IND that I would like to use to index values in another matrix A... thing is IND has a bunch of NaN in it and I get a the error: > > "??? Subscript indices must either be real positive integers or logicals." > > > > when I do > > TempA = A(IND); > > TempA = A(IND(isfinite(IND)) > or > TempA = A(IND(~isnan(IND)) > > Jan Excellent... thank you Jan and Steve. This makes my find function look complicated but does the thing.
From: Jan Simon on 14 May 2010 15:19 Dear Anthony! > > TempA = A(IND(isfinite(IND)) > This makes my find function look complicated but does the thing. Complicated?! Let me remember Matt Fig's: regexprep(A,'([^/]+/)(?!/)','${strrep($1,$1,'''')}') And Jason Breslau's equivalent: regexprep(A,{'.*[^/]/(?!/)', '\s'},{'', '_'}) And Nathan's: cellfun(@(x)strrep(x(max(regexp(x,'[^/]/[^/]'))+2:end),'','_'),A,'uni',false) (all from the same thread here). Have a nice day, Jan
|
Next
|
Last
Pages: 1 2 Prev: find/replace line of code (with carriage return) Next: make a new window in a GUI |