How to change the x-axis values in a plot

199 vues (au cours des 30 derniers jours)
Joe
Joe le 24 Jan 2024
Modifié(e) : Cris LaPierre le 24 Jan 2024
Hi,
Hoping someone can help. I've tried searching for this, and have seen many different replies which seem to relate to changing the labels rather than the values. Essentially, i'm trying to plot the kinetic energy required to accelerate a mass to various different velocities on a route (with the y axis being the kinetic energy - y=0.5*m*v^2). The velocities go up and down.
When i try too input the values to Matlab, the graph i get back plots a line that turns back onitself(see below), rather than continueing in a in the positve x direction, which i assume is because it thinks i want to plot the x-axis with ascending numbers. Is there a way to change the x-axis values to the speicifc velocities?
I want the the x-axis values to be the velocities on my "route" so: 30mph, then 20mph, then 50, 70, 30, 0 (as an example)
Is there a better way to plot this?
Any help would be greatly appreciated.

Réponse acceptée

Cris LaPierre
Cris LaPierre le 24 Jan 2024
Modifié(e) : Cris LaPierre le 24 Jan 2024
In short, no, you can't change the number order of your axes. You can change the scale (logarithmic, for example), and you can change the label displayed (plot by index but display whatever you want as the label), but you cannot have dicontinous values in an axes.
This can be done using xticks and xticklabels and as either a line or bar plot.
m = 100;
v = [30 20 50 70 30 0];
y = 0.5*m*v.^2;
plot(y)
xticklabels(v)
figure
bar(y)
xticklabels(v)
If there is a way to turn your velocities into a continuous data series, that might provide a solution. Perhaps elapsed time of your trip? Something that orders your velocities the way you want.
  1 commentaire
Joe
Joe le 24 Jan 2024
Thank you, this is exactly what i need.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by