How do I create a heatmap filled with NaN values for preset value of rows and columns?
13 次查看(过去 30 天)
显示 更早的评论
采纳的回答
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!




