필터 지우기
필터 지우기

Replace zeros with NaN's - when there are already NaN's in the matrix?

조회 수: 10 (최근 30일)
Hi
I have a large square matrix which is made up of smaller square matrices which have some NaN values. I used 'blkdiag' to combine the matrices diagonally and all the gaps were filled in with zeros.
I now wish to replace all of the zeros in the large matrix (F) with NaN's.
I tried F(find(~F))=NaN but I get an error saying NaN's cannot be converted to logicals, which makes sense but now I'm not sure how I can get round it. I am fairly new to Matlab.
Any help would be much appreciated.

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 6월 9일
No reason for find and you can't convert nans to logicals.
F(F==0) = nan;
  댓글 수: 1
scour_man
scour_man 2011년 6월 9일
Great, thanks. Seems obvious now! And yes its to stop zero values showing up in surf and contour plots in between areas of data. Thank you

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

추가 답변 (2개)

Ivan van der Kroon
Ivan van der Kroon 2011년 6월 9일
Change to double first:
F=double(F);
F(find(~F))=NaN;
Just curious; why would you need this?

Andrei Bobrov
Andrei Bobrov 2011년 6월 9일
F(~isnan(F))=NaN;
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 6월 9일
That'll switch the whole matrix to nans, not just zero values.
Andrei Bobrov
Andrei Bobrov 2011년 6월 9일
Oops! my bug...
Thanks Sean!

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

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by