フィルターのクリア

How to Rescale X Axis in Plot

24 ビュー (過去 30 日間)
Aaron Ouyang
Aaron Ouyang 2022 年 5 月 3 日
編集済み: Les Beckham 2022 年 5 月 3 日
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.

採用された回答

Les Beckham
Les Beckham 2022 年 5 月 3 日
編集済み: Les Beckham 2022 年 5 月 3 日
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.

その他の回答 (1 件)

Voss
Voss 2022 年 5 月 3 日
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)')

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by