Cut a graph ?

조회 수: 7 (최근 30일)
dsq dq
dsq dq 2021년 9월 10일
댓글: dsq dq 2021년 9월 10일
Hi everyone !
I hope my problem will be quite clear. I am trying to plot somethings like this (Photo linked to this topic) and I wrote this :
$figure(1)
p2 = plot(0,0,'red');
bolleen = 1;
for i = 1:10
switch bolleen
case 1
bolleen = 0;
B = 1;
case 0
bolleen = 2;
B = 2;
case 2
bolleen = 1;
B = 0;
end
if B ~= 0
p2.XData(i) = i;
p2.YData(i) = B;
hold on;
end
end
I thought that for the values of i when "bolleen" is equal to 0, it won't plot it, and I would have a "cut graphic". But it seems like it takes the value (0,0) and my graphic is a mess. Thanks for your help !
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 9월 10일
hello
why such a complicated code ?
if you need to plot two lines you can simply do this
plot([1 2],[1 2],'b',[4 5],[1 2],'r');
axis([0 6 0 3]);
dsq dq
dsq dq 2021년 9월 10일
Hello,
thanks for your answer. I forgot to precise that I don't know the lenght of my vectors, and I would like to plot, only one vectors !

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

채택된 답변

Steven Lord
Steven Lord 2021년 9월 10일
If the data to be plotted includes NaN, that point will not be plotted.
x = 1:5;
y = [1 2 NaN 1 2];
plot(x, y)
axis([0 6 0 3]) % Show some border around the plot
  댓글 수: 1
dsq dq
dsq dq 2021년 9월 10일
Oh ok I see. Thanks I did not tihk to that !

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by