How to plot a shape and let the colors change
Show older comments
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 Comment
xander
on 11 Nov 2014
Answers (1)
Chad Greene
on 11 Nov 2014
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)]);
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!