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

17 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 9 de Jun. de 2011
No reason for find and you can't convert nans to logicals.
F(F==0) = nan;
  1 comentario
scour_man
scour_man el 9 de Jun. de 2011
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

Iniciar sesión para comentar.

Más respuestas (2)

Ivan van der Kroon
Ivan van der Kroon el 9 de Jun. de 2011
Change to double first:
F=double(F);
F(find(~F))=NaN;
Just curious; why would you need this?

Andrei Bobrov
Andrei Bobrov el 9 de Jun. de 2011
F(~isnan(F))=NaN;
  2 comentarios
Sean de Wolski
Sean de Wolski el 9 de Jun. de 2011
That'll switch the whole matrix to nans, not just zero values.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by