Colormap for plot function
이전 댓글 표시
Hi, I'm trying to to create my own Finite Element solver and I have a problem with colouring of lines (elements) according to stress inside. I found out that colormap is not originally supported for plot function. Is there any possibility how to do it ?
Lines represents "elements" with width according to cross-sectional area. I would like to color each line according to matrix "stress" (first column is number of element, second column is stress in current element) and colorbar under the plot. Something like this:

Here is my code, thanks in advance for help.
L = 6000; % length of construction [mm]
H = 1299; % height of construction [mm]
D0=30; % initial diameter of element [mm]
%positions of nodes 1-9
nodes = [0 0; L/4 0; L/2 0; 3*L/4 0; L 0; L/8 H; 3*L/8 H; 5*L/8 H; 7*L/8 H];
%connections of nodes
elements = [1 2; 1 6; 2 6; 2 3; 2 7; 3 7; 3 4; 3 8; 4 8; 4 5; 4 9; 5 9; 6 7; 7 8; 8 9];
%cross-sectional areas of elements
S=zeros(size(elements,1),1);
S(:,1)=(pi*D0^2/4);
%Calculated Stress matrix (first column - number of element
%second column - stress in element [MPa])
Stress=[1.0000 40.8404;2.0000 -81.6790; 3.0000 81.6790;4.0000 122.5211;5.0000 -81.6790;6.0000 81.6790;7.0000 122.5211;8.0000 81.6790;9.0000 -81.6790;10.0000 40.8404;11.0000 81.6790;12.0000 -81.6790;13.0000 -81.6808;14.0000 -163.3615;15.0000 -81.6808];
figure(1)
hold on
for i=1:size(elements,1)
x=[nodes(elements(i,1),1) nodes(elements(i,2),1)];
y=[nodes(elements(i,1),2) nodes(elements(i,2),2)];
plot(x,y,'Color',[0 0 1]','LineWidth', sqrt(4*S(i)/pi)/5)
end
axis equal
title 'Shape and Stress '
hold off
채택된 답변
추가 답변 (1개)
darova
2019년 3월 8일
maxs = max(stress(:,2));
mins = min(stress(:,2));
color = jet(255); % get 255 RGB colors
ncol = (cur_stress-mins)/(maxs-mins); % scaling currrent stress to intensity
ncol = round(ncol*255); % number of color
el_color = color(ncol,:); % rgb color of element
카테고리
도움말 센터 및 File Exchange에서 Color and Styling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
