MATLAB Answers

Setting a plot's x-axis by units and not finer data points?

1 view (last 30 days)
No No
No No on 7 Sep 2021
Answered: Steven Lord on 7 Sep 2021
I have a simple issue but I can't seem to ask the right question to find it on Google or this community.
I have the data for a function over 10 seconds, recorded in 10 ms steps. This leaves me with 10000 data points.
When I plot it, the x axis uses the data points and goes from 1 to 10000, but I would like the axis ticks to be for seconds, not thousands of seconds.
What's the easiest way to fix this?

Answers (1)

Steven Lord
Steven Lord on 7 Sep 2021
When you call plot with one data input, the indices of the elements in the vector are used as the X coordinates.
plot((1:10).^2, '-o') % uses 1:10 as the X coordinates
When you call plot with two data inputs, the first is used as the X coordinates and the second the Y coordinates.
plot(11:20, (1:10).^2, '-o') % uses 11:20 as the X coordinates

Products


Release

R2015a

Community Treasure Hunt

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

Start Hunting!