How do I create a heatmap filled with NaN values for preset value of rows and columns?
12 ビュー (過去 30 日間)
古いコメントを表示
I am making multiple heat maps with varying amounts of data. I want to create a blank heatmap of NaN values so all of my maps are 30x15, even if there isn't that much data in each.
How should I go about doing this?
0 件のコメント
採用された回答
dpb
2025 年 3 月 25 日
編集済み: dpb
2025 年 3 月 25 日
HM=heatmap(nan(30,15));
You don't need such; just fill in an array of that size with the actual data at some point chosen for the upper RH corner for the real data to reside.
HR=30; HC=15;
A=nan(HR,HC);
R=20; C=10;
r=floor((HR-R)/2);
c=floor((HC-C)/2);
M=randi(200,[R,C]);
A(r:r+R-1,c:c+C-1)=M;
heatmap(A)
3 件のコメント
Steven Lord
2025 年 3 月 25 日
If you want the data to be centered and you're using release R2023b or later, you can use the paddata function.
A = randi(10, 12, 17);
P1 = paddata(A, [30 28], FillValue = NaN);
P2 = paddata(A, [30 28], FillValue = NaN, Side = "both");
figure
heatmap(A)
figure
heatmap(P1, Title="A is in upper-left corner")
figure
heatmap(P2, Title="A is centered")
dpb
2025 年 3 月 26 日
P1 = paddata(A, [30 28], FillValue = NaN);
P2 = paddata(A, [30 28], FillValue = NaN, Side = "both");
When was the NamedParameterName=Value syntax introduced Steven? That surely confused an old fogey like me for a while until I figured it must be equivalent to and tried
P1 = paddata(A, [30 28], 'FillValue',NaN);
P2 = paddata(A, [30 28], 'FillValue',NaN, 'Side',"both");
to be certain. :)
As we've noted before, I'm still on R2021b for IT conflict-avoidance issues...
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




