How to Print and Save a 2D Array as a Heatmap Image in MATLAB
Imagesc
imagesc
function allows you to display a 2D array as a heatmap. colorbar
is a setting that outputs a color bar indicating the scale.
N=2^8;
p=phantom('Modified Shepp-Logan',N);
figure()
imagesc(p)
colorbar
Saving
Method 1
You can use the saveas
function to save the figure displayed above. The setting gcf
refers to the current figure. Then, the picture below is saved.
N=2^8;
p=phantom('Modified Shepp-Logan',N);
figure()
imagesc(p)
colorbar
saveas(gcf,'phantom.png')
Method 2
You can also save directly from the figure window, as shown in the picture below.