How to change the x-axis values in a plot

200 次查看(过去 30 天)
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.

采纳的回答

Cris LaPierre
Cris LaPierre 2024-1-24
编辑:Cris LaPierre 2024-1-24
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by