not take into account zeros in a graph

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

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2012년 3월 12일

0 개 추천

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

Bart
Bart 2012년 3월 12일
Thnx, helped me. What is [il, il] doing?
Andrei Bobrov
Andrei Bobrov 2012년 3월 12일
index of 'z'
Jan
Jan 2012년 3월 12일
index=find(z) is sufficient, because the 2nd index is not needed.

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

carmen
carmen 2012년 3월 12일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

질문:

2012년 3월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by