Is it possible to convert a heatmap to a Matrix ?

25 ビュー (過去 30 日間)
Fadi Al-kayid
Fadi Al-kayid 2021 年 1 月 8 日
コメント済み: Walter Roberson 2021 年 1 月 8 日
Hey all!
I have a for loop with 29k iterations, i want to store in each iteration a heatmap in a cell array. Now the problem arrises, that every time a new heatmap is created, the last heatmap got deleted and i am ending with 29k emtpy heatmaps that are deleted and only the last one is still available.
I want the same function as a heatmap(counting the apperance of value pairs) but store it as a double matrix. Is there a function which converts the Data of the heatmap into a matrix ? Or how can I stop deleting the heatmap when creating a new one ?
Thanks in advance !
  3 件のコメント
Fadi Al-kayid
Fadi Al-kayid 2021 年 1 月 8 日
Thanks for your respone, but i didn't get it.. How does this work or what diffirence will bring this ?
Kind Regards
Fadi
Walter Roberson
Walter Roberson 2021 年 1 月 8 日
Now the problem arrises, that every time a new heatmap is created, the last heatmap got deleted
Each iteration you can create a new figure or panel or tab to parent the heatmap into, so that the heatmap will not get deleted each time and all of them will be available.
Nominally this solves the problem you stated. It would not, however, solve the problem that 29k graphics objects would be rather slow.

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

回答 (1 件)

Kelly Kearney
Kelly Kearney 2021 年 1 月 8 日
Unlike most Matlab plotting functions, heatmap is annoyingly heavy-handed. It really wants to be used as a quick browsing tool, with very little customization allowed.
You can extract the color data from it:
load patients
tbl = table(LastName,Age,Gender,SelfAssessedHealthStatus,...
Smoker,Weight,Location);
h = heatmap(tbl,'Smoker','SelfAssessedHealthStatus');
cdata = h.ColorData;
Alternatively, you may want to look some histogram functions (e.g. histcounts2) to calculate heatmap-like values without the plotting overhead.
  2 件のコメント
Fadi Al-kayid
Fadi Al-kayid 2021 年 1 月 8 日
First of all, thank you very much!
Do you know if its possible to extract the whole data out of the heatmap, for example i have a 11x11 grid and when i am extracting the data using h.ColorData it return a matrix only with the dimension in which the counts are bigger than zero ..
Kelly Kearney
Kelly Kearney 2021 年 1 月 8 日
Do you have a small example of what you're looking for? The XData, YData, and ColorData properties hold most of the info you'd need, I think, though it may vary based on your specific example.
Really, with 29000 iterations, some batch histogram calculations are probably going to be more efficient and flexible than trying to extract the data you need from a heatmap chart, but again, it depends on your exact use case.

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

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by