How to plot a shape and let the colors change

Hello everyone,
I made a program that loops over an [100x1] matrix called ct. So for each timestep, the [100x1] matrix is update with new values.
figure
for n = 1:timeStep;
...
...
ct=ct_new
plot ct
end
I want to visualise the values of ct as folows: Each cell of the ct matrix represents an area with a certain Diameter and Height:
D_segment = a [100x1] matrix (each segment has a different diameter) z = a [100x1] matrix are the coordinates of the heights (with steps dz).
N=100;
L=19;
dz=L/(N-1);
z=0:dz:L;
I want to plot the area's of each each segment and then color the area with value of ct. The result then should be that many squares (each with its own diameter) are plotted above each other and they should change color during the loop.
Thank you very much!

댓글 수: 1

I managed to get the plot:
square=0*z;
figure
for i=1:N
square(i)=rectangle('position',[-D_segment(i)/2,z(i),D_segment(i),dz]);
set(square(i), 'LineStyle', 'none')
set(square(i), 'FaceColor', [0 0 1])
hold on
end
axis('equal')
colorbar
colormap jet
caxis([0 0.7])
hold off
When i execute this commando, i get the correct form/shape that i want. However, now i want to let the facecolor change each timestep of the main loop. The values of the ct matrix vary between 0 and 0.6 0 should get the color blue, 0.6 must become red Any suggestions?

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

답변 (1개)

Chad Greene
Chad Greene 2014년 11월 11일

0 개 추천

With rgbmap,
colors = rgbmap('red','blue',N);
for i=1:N
square(i)=rectangle('position',[-D_segment(i)/2,z(i),D_segment(i),dz]);
set(square(i), 'LineStyle', 'none')
set(square(i), 'FaceColor', colors(N,:))
hold on
end
Or manually, define colors as
colors([linspace(0,1,N)' linspace(1,0,N)' zeros(N,1)]);

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

질문:

2014년 11월 11일

답변:

2014년 11월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by