필터 지우기
필터 지우기

Why can´t plot a line avoinding repeated lines?

조회 수: 2 (최근 30일)
Albert Johan Mamani Larico
Albert Johan Mamani Larico 2020년 12월 12일
댓글: Albert Johan Mamani Larico 2020년 12월 12일
Why the following code doesn´t show the expected lineplot?. Can someone explain to me what's wrong with my code? Thanks
C=0.0893;
a=1.5532;
n=2.9718
x=[2.21 2.24 2.46 2.58 2.12 2.27 3.12 3.7 3.08 2 1.47 2.43 2.16...
3.48 1.61 0.93 1.74 2.3 2.38 2.33 2.38 2.06 2.76 3.5 0.9 2.33...
3 4.31 4.21 2.27 2.16 3.95 2.08 3.42 2.81 3.9 4.87 5.32 3.93...
4.12 5.17 5 5.54 3.11 4.9 5.22 3.48 3.07 2.88 2.32 2 2.7 4 0.33...
3.62 3.47 2 1.92 1.8 1.82 3.39 3.18 3.83 4.11 3.655 2.55 2.22 3.77 2.96];
y=C*(x+a).^n;
plot(x,y)

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 12일
편집: Cris LaPierre 2020년 12월 12일
What do you expect? A single line or multiple line series?
Your line looks the way it does because your X values are not linearly increasing. Instead, they increase and decrease in value, which results in your line looking the way it does. The line is drawn in the order your points specify, the first to the second to the third, etc.
Perhaps you don't want a line. Perhaps you just want the data points. In that case, add a linespec to your plot command, or use scatter. If you do want the line, then you'll have to sort your data.
C=0.0893;
a=1.5532;
n=2.9718;
x=[2.21 2.24 2.46 2.58 2.12 2.27 3.12 3.7 3.08 2 1.47 2.43 2.16...
3.48 1.61 0.93 1.74 2.3 2.38 2.33 2.38 2.06 2.76 3.5 0.9 2.33...
3 4.31 4.21 2.27 2.16 3.95 2.08 3.42 2.81 3.9 4.87 5.32 3.93...
4.12 5.17 5 5.54 3.11 4.9 5.22 3.48 3.07 2.88 2.32 2 2.7 4 0.33...
3.62 3.47 2 1.92 1.8 1.82 3.39 3.18 3.83 4.11 3.655 2.55 2.22 3.77 2.96];
y=C*(x+a).^n;
% Set LineSpec
plot(x,y,'o')
% Use scatter
figure
scatter(x,y)
% Sort x data first
x=sort([2.21 2.24 2.46 2.58 2.12 2.27 3.12 3.7 3.08 2 1.47 2.43 2.16...
3.48 1.61 0.93 1.74 2.3 2.38 2.33 2.38 2.06 2.76 3.5 0.9 2.33...
3 4.31 4.21 2.27 2.16 3.95 2.08 3.42 2.81 3.9 4.87 5.32 3.93...
4.12 5.17 5 5.54 3.11 4.9 5.22 3.48 3.07 2.88 2.32 2 2.7 4 0.33...
3.62 3.47 2 1.92 1.8 1.82 3.39 3.18 3.83 4.11 3.655 2.55 2.22 3.77 2.96]);
y=C*(x+a).^n;
plot(x,y)
  댓글 수: 1
Albert Johan Mamani Larico
Albert Johan Mamani Larico 2020년 12월 12일
Thanks! I was looking for a single line and this works

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by