Data with NaN

3 visualizaciones (últimos 30 días)
Ola Kalen
Ola Kalen el 28 de Mzo. de 2011
Comentada: Vishnu Keyen el 18 de Ag. de 2021
Hi
I´m having trouble plotting data that include NaNs. I load a data-matrix using textread. I want to skip plotting entries that are NaNs.
For example:
x=[4 2 NaN 9]
y=[3 5 7 8]
Now I want to plot x against y for the 1st, 2nd and last entries (skipping the third). Are tips how to do this?

Respuesta aceptada

Teja Muppirala
Teja Muppirala el 28 de Mzo. de 2011
If you wanted to keep a line connecting them:
I = ~isnan(x) & ~isnan(y);
plot(x(I),y(I))
  1 comentario
Hernan Larriva
Hernan Larriva el 23 de Sept. de 2019
Thanks , regards from Barcelona!

Iniciar sesión para comentar.

Más respuestas (3)

John D'Errico
John D'Errico el 28 de Mzo. de 2011
Have you bothered trying to plat the data? What did plot do when you did try it? For example,
plot(x,y,'o')
Try things in MATLAB! Don't just give up and assume it will fail! READ THE HELP! Look at the arguments.

David Young
David Young el 28 de Mzo. de 2011
Unless I've misunderstood your question,
plot(x,y,'o');
does exactly what you are asking.
  1 comentario
Vishnu Keyen
Vishnu Keyen el 18 de Ag. de 2021
I have 1*1000 array
I have values only in every 100th indice.
x=nan(1,1000);
x(1:100:end)=rand(1,10);
y = 1:1000;
it will plot the data when i say
plot(x,y,'o-')
But there won't be any line between the points.
I want to plot all the values, ignore the nans, and still get a line connected between them.

Iniciar sesión para comentar.


Ola Kalen
Ola Kalen el 28 de Mzo. de 2011
Thanks Teja, that solves my problem
Ola
  1 comentario
Teja Muppirala
Teja Muppirala el 28 de Mzo. de 2011
Sure, no problem. I assumed that's probably what you were trying to do.
It helps to be very thorough in writing in your question though. In other words don't just say you are "having trouble", but say what that trouble is ("the line connecting them disappears!").
Sometimes people have difficulty interpreting exactly what you wanted to ask, and then you are less likely to get the answer that you were looking for.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical 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