How to plot 2D colormap or heatmap?

조회 수: 15 (최근 30일)
ishita agrawal
ishita agrawal 2017년 6월 28일
답변: Image Analyst 2018년 8월 29일
I have 2 matrices, x and y each containing 100-200 datapoints. I want to plot heatmap (or 2D colormap) to show density. For example, x= 1:100; for i=1:100 y=rand(0.01:1); end

채택된 답변

Image Analyst
Image Analyst 2017년 6월 28일
Try scatteredInterpolant() to generate a 2-D image from randomly scattered points, then use imshow() to display it, and colormap() to apply a colormap, and colorbar() to show a bar alongside the image.
  댓글 수: 1
Anjali Gerg
Anjali Gerg 2018년 8월 29일
while applying imshow() function to the object generated after scatteredInterpolation, it says the input number must be a number or logical. Can you suggest how we can apply imshow() after using scatterInterpolation?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2018년 8월 29일
Here is a snippet from my program:
% Make the scattered interpolant.
F = scatteredInterpolant(xi, yi, dataValues)
% Get a grid of points at everypixel location in the RGB image.
[xGrid, yGrid] = meshgrid(1:columns, 1:rows);
xq = xGrid(:);
yq = yGrid(:);
% Evaluate the interpolant at query locations (xq,yq).
vq = F(xq, yq);
fittedImage = reshape(vq, rows, columns);
imshow(fittedImage, []);

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by