Plot with x-axis label in Hour instead of Second

4 ビュー (過去 30 日間)
Harsimran Singh
Harsimran Singh 2022 年 8 月 10 日
コメント済み: dpb 2022 年 8 月 10 日
Hello Guys,
I am trying to plot a graph for data attached, that has temperature.
When I plot it using
T = readtable("Q.csv");
plot(T.Temp)
xlabel('Time(s)')
ylabel('Temp(c)')
grid on
grid minor
it gives me a plot given in attached file
Since I don't have time/duration on data, therefore matlab is defaulting time between each cell as 1 sec(which is conincidently correct on my data).
I would like to make a plot with x-axis units in Hours instead of minutes with given data.
I am tying to do this by creating an array for time(HR) and concatenating with data but no luck. I have ~50 excel files which are similar to attached file.
Any help/suggestion would be appreciated.
Thanks

採用された回答

dpb
dpb 2022 年 8 月 10 日
tT=readtable("Q.csv");
tT=addvars(tT,seconds(1:height(tT)).','before','Temp','NewVariableNames','T');
tT.T.Format='h';
plot(tT.T,tT.Temp)
xlabel('Time')
ylabel('Temp(\circC)')
grid on
grid minor
  2 件のコメント
Harsimran Singh
Harsimran Singh 2022 年 8 月 10 日
It works, thanks
dpb
dpb 2022 年 8 月 10 日
The above will give default plot units of the units in the data table -- you can also leave them as seconds and then change the format of the x-axis datetimeruler object.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by