Use timetable as x axis in heatmap

5 ビュー (過去 30 日間)
Amir Hosein Shokouhy
Amir Hosein Shokouhy 2022 年 3 月 10 日
回答済み: Benjamin Kraus 2022 年 3 月 12 日
I have this time table (t_avg) and I want to use it as the x axis for a heatmap of my load data (load_avg).
I am currently using this code but the x axis is not the correct time:
figure (4)
XLabels = 1:size(load_avg,1);
CustomXLabels = string(XLabels);
CustomXLabels(mod(XLabels,10) ~= 0) = " ";
h.XDisplayLabels = CustomXLabels;
caxis([0 max(max(load_avg))])
colormap jet
I tried using this code but it didn't work:
I'd appreciate it if any one can help.


Peter Perkins
Peter Perkins 2022 年 3 月 11 日
Amir, according to your screenshots, you do NOT have a timetable. You have a table containg one datetime variable, and a separate double matrix. You need to make a timetable. One possibility might be
tt = timetable(t_avg.Time,load_avg)
another might be
tt = array2table(load_avg,'RowTimes',t_avg.Time)
but I have no idea what you are doing, so I can't really say how to make the timetable.
  4 件のコメント
Peter Perkins
Peter Perkins 2022 年 3 月 11 日
help datetime/string


その他の回答 (1 件)

Benjamin Kraus
Benjamin Kraus 2022 年 3 月 12 日
In this case, you may be better off with something like imagesc or surf instead of heatmap. heatmap is designed for cases in which your x and y dimensions are categorical in nature. In your case, your x-axis is time, which is continuous (even if your data has been discretized). This will let you work with the datetime data more natively, rather than resorting to manually generating your tick labels.
I recommend something like this:
y = 1:size(load_avg,2);
surf(t_avg.Time, y, load_avg');
axis tight
caxis([0 max(max(load_avg))])
colormap turbo % turbo is more percetually uniform than jet, but otherwise very similar


Community Treasure Hunt

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

Start Hunting!

Translated by