maximusdooku February 2016
How can I get the values of non-NAN elements in a Matrix?
I have a huge matrix for which I need the row, column and values of non-NAN elements.
This works when I have zero (instead of NAN) and non-zero elements:
[rwpRow, rwpCol, rwpVal] = find( zerotest )
But when I do this for NAN matrix, I get all 1 values.
[rwpRow, rwpCol, rwpVal] = find(~isnan(nantest))
How can I do this?
Daniel February 2016
The input to
find is a logical array which is 1 for all non-nan elements. That 1 is what you get and
find does not "see" the actual values. You have to split that up into separate calls:
[rwpRow, rwpCol] = find(select)
Random Guy February 2016
You can only get the rows and columns from the call to
find since it finds the 1s in
~isnan(nantest). Get all the non NaN values in the matrix in another step:
[rwpRow, rwpCol] = find(~isnan(nantest));
vals = nantest(~isnan(nantest));
Asked in February 2016
Viewed 1,176 times
Answered 2 times
Leave an answer
Quote of the day: live life