Why can´t plot a line avoinding repeated lines?
1 次查看(过去 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)
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 中查找有关 Scatter Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!