How do I create a heatmap filled with NaN values for preset value of rows and columns?
11 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
dpb
on 25 Mar 2025
Edited: dpb
on 25 Mar 2025
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 Comments
Steven Lord
on 25 Mar 2025
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
on 26 Mar 2025
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...
More Answers (0)
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!