Why can´t plot a line avoinding repeated lines?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Albert Johan Mamani Larico
am 12 Dez. 2020
Kommentiert: Albert Johan Mamani Larico
am 12 Dez. 2020
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 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 12 Dez. 2020
Bearbeitet: Cris LaPierre
am 12 Dez. 2020
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Line Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!