Why can´t plot a line avoinding repeated lines?
2 ビュー (過去 30 日間)
古いコメントを表示
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/458765/image.jpeg)
0 件のコメント
採用された回答
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)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!