Effacer les filtres
Effacer les filtres

Why can´t plot a line avoinding repeated lines?

2 vues (au cours des 30 derniers jours)
Albert Johan Mamani Larico
Albert Johan Mamani Larico le 12 Déc 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)

Réponse acceptée

Cris LaPierre
Cris LaPierre le 12 Déc 2020
Modifié(e) : Cris LaPierre le 12 Déc 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)
  1 commentaire
Albert Johan Mamani Larico
Albert Johan Mamani Larico le 12 Déc 2020
Thanks! I was looking for a single line and this works

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by