Display of nodal values of a matrix

4 views (last 30 days)
Charles
Charles on 20 Mar 2024
Answered: Aquatris on 20 Mar 2024
I made a code to calculate the temperature of nodes, compiled as a matrix, in a 2D space given set boundary temperatures. I was able to get a figure for a temperature contour but now I need to display the values in the matrix as a figure similar to how shown below (excluding T1, T2, etc.).

Answers (2)

Mario Malic
Mario Malic on 20 Mar 2024
Here is a function that allows that text

Aquatris
Aquatris on 20 Mar 2024
You can use patch and text functions:
nrRow = 4; % number of rows
nrCol = 6; % number of columns
recW = 0.5;% rectangle width
recH = 0.5;% rectangle height
temps = round(rand(21,1)*5000); % random temperature values
for i = 0:20
nodeName{i+1} = sprintf('T_{%d}',i+1); % name of node
pos(i+1,:) = [mod(i,nrCol) nrRow-floor(i/nrCol)]; % position of node
end
% rectangle x and y coordinates
x = [pos(:,1)'+recW/2
pos(:,1)'+recW/2
pos(:,1)'-recW/2
pos(:,1)'-recW/2];
y = [pos(:,2)'+recH/2
pos(:,2)'-recH/2
pos(:,2)'-recH/2
pos(:,2)'+recH/2];
figure(1)
clf
patch(x,y,'g') % draw rectangles
text(pos(:,1)-recW/4,pos(:,2),nodeName) % write node names
text(pos(:,1)-recW/2,pos(:,2)-recH/1.5,string(temps)+' K') % write temperature values

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!