How to Rescale X Axis in Plot
22 views (last 30 days)
Show older comments
Hi,
I'm plotting a 1470x28 double and I need to rescale the x axis. Right now, the x axis shows data from 0 to 1470, but I need to convert the units of the x axis so that they show the same data, but it says 0 to 2940 instead. Basically i just want the 1500 on the bottom right to become 3000 and I want the data to still extend to the 3000 tick. I attached a pic of what I currently have. Thanks. 

0 Comments
Accepted Answer
Les Beckham
on 3 May 2022
Edited: Les Beckham
on 3 May 2022
Since you didn't show the code you used to generate the plot or include the data, I'll have to guess what the problem might be.
data = rand(28,1470); % made up data
for i = 1:28
data(i,:) = data(i,:) + i; % offset the data so it won't be on top of each other
end
plot(data') % maybe you were plotting without an x vector?
t = linspace(0, 1470*2, 1470); % create a vector specifying the data to use for the x axis
figure
plot(t, data) % plot with new x data
Note the new range on the x axis.
0 Comments
More Answers (1)
Voss
on 3 May 2022
Maybe this example will show you how you can do that.
First, I'll create a random matrix the same size as yours:
y = rand(1470,28);
And plot it like you are doing now (maybe):
subplot(3,1,1)
plot(y)
title('plot(y)')
That plots y against the sample numbers 1:1470.
Another way to do that is to explicitly use those numbers as x (the first argument) in plot:
subplot(3,1,2)
plot(1:1470,y) % same as first plot
title('plot(x,y)')
If you do it that way, then you can make x whatever you want (in this case, multiplying by 2):
subplot(3,1,3)
plot(2*(1:1470),y) % doubling x
title('plot(2*x,y)')
0 Comments
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!