How do I create a heatmap filled with NaN values for preset value of rows and columns?

12 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

dpb
dpb am 25 Mär. 2025
Bearbeitet: dpb am 25 Mär. 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 Kommentare
Steven Lord
Steven Lord am 25 Mär. 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
dpb am 26 Mär. 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...

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by