필터 지우기
필터 지우기

Need to plot speed heatmap

조회 수: 21 (최근 30일)
Laxmi Bhatta
Laxmi Bhatta 2023년 3월 14일
댓글: Laxmi Bhatta 2023년 3월 14일
I have an excel sheet having data of time, distance(postmile) and speed in three columns
I have to plot 2d high resolution heatmap of speed as follows; time in x-axis, distance(postmile) in y axis and speed in z axis with color. Can anyone help me to provide matlab code for this

답변 (1개)

Anurag Ojha
Anurag Ojha 2023년 3월 14일
Hi, Laxmi
To draw a heatmap for 3 variables you can simply turn your data into an image, for example, a 1000x1000 image. Then display the image using imshow or “image” and then use “colormap” and “colorbar.
%Taken 3 variables in your case time,displacement and speed
x = 1:100;
y = 2:102;
z = 50:150;
% Doing this so that any unassigned values
% (like you don't have every single possible x and y value in your data) will be
% set to the mean value of what data you do have.
minx = min(x);
maxx = max(x);
miny = min(y);
maxy = max(y);
meanValue = mean(z);
heatMapImage = meanValue * ones(1000, 1000);
% Here creating the heatmap and storing it in heatMapImage array
for k = 1 : length(x)
column = round( (x(k) - minx) * 100 / (maxx-minx) ) + 1;
row = round( (y(k) - miny) * 100 / (maxy-miny) ) + 1;
heatMapImage(row, column) = z(k);
end
%Convert the array to image using imshow and adding colorbar
imshow(heatMapImage, []);
colormap('hot');
colorbar;
To further explore you can refer to below links:
Hope it helps!
  댓글 수: 1
Laxmi Bhatta
Laxmi Bhatta 2023년 3월 14일
Hi there
I have attached table, I am new to MATLAB, if you could make code for plotting one heatmap having time in x (column3) axis, postmile in y axis (column 2) and speed (column 4) in z axis would be appreciated.
Thanks

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by