not take into account zeros in a graph

1 visualización (últimos 30 días)
Bart
Bart el 12 de Mzo. de 2012
Hi,
I have to make a graph of a few points. In these points there are zeros, like [3 0 2 0 0 0 5 0 2 0 0 0 4 0 1 0 0 8]. I want to connect the positive integers, but without the line going trough the zeros. How can I manage this?
Kind Regards, Bart

Respuestas (2)

Andrei Bobrov
Andrei Bobrov el 12 de Mzo. de 2012
z = [3 0 2 0 0 0 5 0 2 0 0 0 4 0 1 0 0 8]
[i1,i1] = find(z)
plot(i1,z(i1));grid on
  3 comentarios
Andrei Bobrov
Andrei Bobrov el 12 de Mzo. de 2012
index of 'z'
Jan
Jan el 12 de Mzo. de 2012
index=find(z) is sufficient, because the 2nd index is not needed.

Iniciar sesión para comentar.


carmen
carmen el 12 de Mzo. de 2012
another way is to use
z=[3 0 2 0 0 0 5 0 2 0 0 0 4 0 1 0 0 8];
z(z=0)=[] % now z == [3 2 5 2 4 1 8]
plot(z)
this codes removes the zero-valued indices, that means that the size z will decrease by the amount of zero values that were there before. however, not always this makes sense to a problem, particularly if the x-axis-spacing needs to stay unchanged.

Categorías

Más información sobre Graph and Network Algorithms 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