MATLAB Answers

Cut a graph ?

6 views (last 30 days)
dsq dq
dsq dq on 10 Sep 2021
Commented: dsq dq on 10 Sep 2021
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 :
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;
if B ~= 0
p2.XData(i) = i;
p2.YData(i) = B;
hold on;
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 !
dsq dq
dsq dq on 10 Sep 2021
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 !

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 10 Sep 2021
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 Comment
dsq dq
dsq dq on 10 Sep 2021
Oh ok I see. Thanks I did not tihk to that !

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!