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?

Answers


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:

select=~isnan(nantest)
[rwpRow, rwpCol] = find(select)
rwpVal=nantest(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));

Post Status

Asked in February 2016
Viewed 1,176 times
Voted 8
Answered 2 times

Search




Leave an answer