How to plot predefined area in picture colorcoded for a simulation?
2 次查看(过去 30 天)
显示 更早的评论
Hello!
I am working on a simulation right now where I calculate the Heat Transfer in a device (Turbine-Injector). For this I used a Net-Work-Model for which I needed to split the Injector into different parts and now each part is represented by an element in this model. If I run the simulation I now get a temperature for each vertice between the elements for the different timesteps.
I have a 2D drawing of the injector and now my plan is to define areas in this picture manually that correspond to the different vertices. In a next step I want to run a script so that these predefined areas change with the color according to the values I got from my simulation for the different timesteps (see picture to maybe better understand).
Does anyone have an idea on how to do this or if I even should use MATLAB for this (maybe Paraview would be better)
Thanks a lot!
BB
0 个评论
回答(1 个)
Divyajyoti Nayak
2025-6-20
The 'imread' function can be used to read your image and then the 'image' function can be used to plot it on cartesian axes in a figure.The colored areas can be plotted on top of this image using the 'patch' function. The color of this 'patch' object can be changed by setting the 'FaceColor' property. Here's some sample code to demonstrate:
% Create a figure
figure;
% Create axes
ax = axes; % Full figure size
% Load an image (replace 'your_image.png' with your image file)
img = imread('pic_matlab_question.png');
% Display the image in the axes
image(ax, img);
% You can add other plots/patches on top of the image
hold(ax, 'on');
p1 = patch([20,150,150,20],[10,10,70,70],'blue');
%You can change the color of the patch using 'FaceColor' property
p1.FaceColor = 'red';
%Dummy time series data
time = linspace(0, 10, 100);
data = linspace(0,1,100);
%Changes colour of patch according to the time series data
for i = 1:100
p1.FaceColor = [data(i), 0, 0];
pause(0.1);
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Red 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!