matlab plot, interrupted line when y is zero

조회 수: 5 (최근 30일)
Birsen Ayaz-Maierhafer
Birsen Ayaz-Maierhafer 2019년 8월 23일
답변: Star Strider 2019년 8월 23일
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*-')

답변 (1개)

Star Strider
Star Strider 2019년 8월 23일
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.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by