matlab plot, interrupted line when y is zero
6 views (last 30 days)
Show older comments
Hi,
I have a data that has some zero values but I would like to avoid to plot these values but I want a continues line between the previous and one after the data point. When I searched the web there are method to omit the zero values but the lines are broken. Instead I want to avoid the y=0 values but the code should plot a continues line before and after the y=0 values, Please see the plot. I would like to pass the data points of 5 and 7 and just connect the line between data point 4 and 6 and 6 and 7. Any idea? Thank you
figure(4)
x1=ModData(1:end,1);
x2=ExpData(1:end,1);
Mod=PD_Mod(:,7);
Exp=PD_Ex(:,4);
plot(x1,Mod,'gs-', x2,Exp,'r*-')
0 Comments
Answers (1)
Star Strider
on 23 Aug 2019
Try this, using your own ‘x’ and ‘y’ vectors:
x = 0:10; % Create Data
y = randi([0 5], 1, 11); % Create Data
xnew = x;
ynew = y;
xnew(y == 0) = [];
ynew(y == 0) = [];
figure
plot(x, y)
hold on
plot(xnew, ynew)
hold off
grid
Experiment to get the result you want.
0 Comments
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!