フィルターのクリア

Rescale an axis in other steps without creating vector

3 ビュー (過去 30 日間)
Leonard
Leonard 2013 年 12 月 3 日
コメント済み: sixwwwwww 2013 年 12 月 3 日
Hello,
I have the following problem: I have for example 1000 measurement points but in 0.02 second steps. In the plot I want to have not a scale from 0 to 1000 but from 0 to 20 (=1000*0.02). As I don't know the length of my data points, I cannot create a vector in 0.02 steps for the x-axis because then Matlab returns that the vectors must be the same lengths.
Is there a possibility, just to divide the x-axis by 50?
Thanks, Leo

回答 (4 件)

sixwwwwww
sixwwwwww 2013 年 12 月 3 日
編集済み: sixwwwwww 2013 年 12 月 3 日
You can control your x-axis by plotting your data against your time as follows:
y = rand(1, 1000); % your data
x = linspace(0, 0.02, numel(y)); % your time series
plot(x, y) % your plot of data against time series
or you can use 'xlim' for this purpose. see
doc xlim
for more information

Leonard
Leonard 2013 年 12 月 3 日
編集済み: Leonard 2013 年 12 月 3 日
That's exactly my point: With this I can't do it.
I don't want the first 20 measurement points. I want to have all 1000 measurement points, but the x-axis shall contain the numbers 0 to 20 (instead of 0 to 1000).
I hope, you now get, what I mean. Thx

sixwwwwww
sixwwwwww 2013 年 12 月 3 日
編集済み: sixwwwwww 2013 年 12 月 3 日
Try this:
y = rand(1, 1000); % your data
x = linspace(0, 20, numel(y)); % your time series
plot(x, y) % your plot of data against time series
It will plot 1000 points within range of 0 to 20

Leonard
Leonard 2013 年 12 月 3 日
OK, this wasn't the solution either but I found out a way for myself now. Looks like this (for your interest or anybody else who needs it):
plot(0.02:0.02:numel(y)/50,y)
y is the function.
  3 件のコメント
Leonard
Leonard 2013 年 12 月 3 日
In your case you have determined that the length is 20 seconds. But in my case this value is variable. So sometimes it's 20 seconds, sometimes 50 seconds or whatever other value.
But I just figured out, that your way could be also possible if I just choose the end point as a variable as well like this:
x = linspace(0, numel(y)/50, numel(y));
Thanks for your help again!
sixwwwwww
sixwwwwww 2013 年 12 月 3 日
In my case 20 is not fix. in the following line of code you can just replace 20 by any value then it will also work
x = linspace(0, 20, numel(y));
Good luck!

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by