How to choose overlapping data from two matrices?

I am trying to use a bit of code that uses two pieces of data to generate another (input a and b, get c) and then plot c by loction. 'a' and 'b' come from data collected from an area but not from the same exact locations, so I have used griddata to generate two matrices with interpolated 'a' and 'b' values, and plan to calculate the corresponding 'c' values from these. This way, I should be able to plot 'c' by location using pcolor.
The problem that I am having i that the calculation uses a 'root' function, and thus will not accept NaNa (or presumeably '0'). Since my original data was not collected in a nice square, I have some entire columns of NaN in my interpolated data matrices. I also have some columns with data for 'a' but no data for 'b', see example below:
'a': [NaN NaN 3 5 NaN; NaN 2 4 1 NaN; NaN 3 NaN 3 4]
'b': [NaN 3 2 4 NaN; NaN 1 2 2 3; NaN NaN 3 1 NaN]
Is there a way to replace the 'NaN' in my matrices with something else? Or perhaps extract only the data when a value appears in the same place in both matrices 'a' and 'b'? I'm not sure the second option would work, as I then want to plot the results versus location (original x and y).
Thanks for your help! Jen

 채택된 답변

Oleg Komarov
Oleg Komarov 2011년 8월 27일

0 개 추천

Index the NaNs with isnan:
idxa = isnan(a);
idxb = isnan(b);
Then combine the indexes with an or and negate it to find where both matrices have NON nans or use the indexes singularly to replace the nans with 0 or smt else:
a(isnan(a)) = 0;

댓글 수: 2

Jen
Jen 2011년 8월 28일
I have attempted to use the a(isnan(a))=0; however, this has rounded the rest of my data for four decimal places, which is insufficient to tell them apart!
It's a matter of display.
Try format long in the command window.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 NaNs에 대해 자세히 알아보기

태그

질문:

Jen
2011년 8월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by