Labelling of x axis

1 回表示 (過去 30 日間)
Telema Harry
Telema Harry 2021 年 5 月 31 日
コメント済み: Telema Harry 2021 年 6 月 9 日
Hello Programmers,
I have an hourly data and I used a step size of 0.1 in my simulation.
I used 12 hours worth of data in my simulation.
I will like the x-axis of my graph to be in hours stead of the number of points.
please how can I do that?
  2 件のコメント
Mathieu NOE
Mathieu NOE 2021 年 5 月 31 日
hello
there's something missing in your question : step size of 0.1 : unit ? second ?
if you have the amount of samples and the sampling rate , it's fairly strightforward to compute the xaxis values in seconds / minutes or hours :
assuming a step size of 0.1 second :
dt = 0.1;
samples = length(data);
x_axis_hours = (0:samples-1)*dt/3600;
plot(x_axis_hours,data);
Telema Harry
Telema Harry 2021 年 6 月 9 日
編集済み: Telema Harry 2021 年 6 月 9 日
Thank you for the feedback.

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

採用された回答

Constantino Carlos Reyes-Aldasoro
Constantino Carlos Reyes-Aldasoro 2021 年 5 月 31 日
There are 2 ways to solve this:
First is to plot in the actual hours instead of the points of the matrix that is holding the data, so, say your values are stored every second, instead of plotting
plot(x,y)
you should plot
plot(x/3600,y)
and that would adjust the values of the x-axis.
The second way is to manipulate the values that are displayed on the x-axis, these are called the ticks and tick labels, for example:
>> plot(1:20,sin(1:20))
>> h1=gca; %you are grabbing the handles of the axis
>> h1.XTick
ans =
Columns 1 through 7
0 2 4 6 8 10 12
Columns 8 through 11
14 16 18 20
>> h1.XTickLabel
ans =
11×1 cell array
{'0' }
{'2' }
{'4' }
{'6' }
{'8' }
{'10'}
{'12'}
{'14'}
{'16'}
{'18'}
{'20'}
>>
So you can change the values of XTickLabel. I would suggest to try the first method and see if that works.
Hope this solves your problem.
  1 件のコメント
Telema Harry
Telema Harry 2021 年 6 月 9 日
Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by