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개)
Chad Greene
2014년 11월 11일
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에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!