Create a heat map using uneven spatial distributed sensor data

조회 수: 14 (최근 30일)
AS
AS 2020년 2월 5일
답변: Jaswanth 2024년 10월 18일
Hallo,
I have 10 data set with values every 5 minute. I have also the coordinates of the sensor locations X & Y.
% Coordinates
X = [27 63 63 54 130 179.5 179.5 196 103 196];
Y = [13.4 28.8 113.2 144 3.8 28.8 115.5 129.6 71 67];
% The grid of ploting the contours
xlinl=linspace(0,230,47);
ylinl=linspace(0,160,33);
[X,Y]=meshgrid(xlinl,ylinl);
Can someone help me how can I create a contour map by using these data per time step?
At the end I would like to create a movie by showing the spatial temperature distribution and how is changing during the time.
Thanks in advance

답변 (1개)

Jaswanth
Jaswanth 2024년 10월 18일
Hi,
To create a contour map and a movie that visualizes the spatial temperature distribution over time using MATLAB, start by organizing your temperature data corresponding to the sensor coordinates. Use “griddata” to interpolate this data over a grid due to the uneven sensor distribution. For each time step, generate contour plots with “contourf” to visualize the temperature distribution, using a color gradient to indicate different levels.
Capture these visualizations as a movie using “VideoWriter” function, compiling frames into a cohesive video to show how the distribution evolves.
Please refer to the following example code demonstrating the process described above:
% Sensor coordinates
sensorX = [27, 63, 63, 54, 130, 179.5, 179.5, 196, 103, 196];
sensorY = [13.4, 28.8, 113.2, 144, 3.8, 28.8, 115.5, 129.6, 71, 67];
% Example temperature data for 10 time steps
% Replace this with your actual data
temperatureData = rand(10, numel(sensorX)); % Random data for illustration
% Grid for contour plotting
xlin = linspace(0, 230, 47);
ylin = linspace(0, 160, 33);
[X, Y] = meshgrid(xlin, ylin);
% Set up the video writer
v = VideoWriter('temperature_distribution.avi');
open(v);
% Loop through each time step
for t = 1:size(temperatureData, 1)
% Interpolate the temperature data onto the grid
Z = griddata(sensorX, sensorY, temperatureData(t, :), X, Y, 'cubic');
% Plot the contour map
contourf(X, Y, Z, 20, 'LineColor', 'none');
colorbar;
axis equal;
axis([0 230 0 160]);
% Capture the plot as a frame
frame = getframe(gcf);
writeVideo(v, frame);
pause(0.1); % Pause for a short duration for visualization
end
% Close the video writer
close(v);
I hope the solution provided above is helpful.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by