How to assign different colours to the "levels" of a cylinder

1 次查看(过去 30 天)
Hello everyone,
As the title says, I need to specify different colours for the segments composing a cylinder.
I built my cylindric structure using this .m file on File Exchange:
since I needed the structure to have different radius for every level.
Now, I have a vector with some values (let's call it x). What I'd like to do is to assign some colours to these values (say, if a value is in a certain range, assign to it colour blue). Then, using the data in x, I'd like to specify for every level of the cylinder the corresponding colour information stored in x.
Hope to have been clear enough.
Any help would be appreciated.
  17 个评论
Vittorio
Vittorio 2014-7-17
Thank you very much! That solved my doubts. You may want to copy-paste the text as an answer, so I can give you the appropriate feedback.

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2014-7-17
If you are trying to associate levels to colours, then with your 14 levels, you could define a 14x3 matrix where each row is a colour given by an RGB value
colours = zeros(14,3);
colours(1,:) = [1 0 0]; % red
colours(2,:) = [0 1 0]; % green
colours(3,:) = [0 0 1]; % blue
colours(4,:) = [0.6784 0.8471 0.9020]; % light blue
etc.
The above is an example only. Now initialize C in such a way that each element is assigned a value from 1 through 14 (for each of the 14 levels) given the contents of Z. In your example, your first row of Z is all zeros. If all these correspond to the first level, then set
C(1,:) = 1;
In the second row of Z, all values are 2.3. If this corresponds to the second level, then set
C(2,:) = 2;
Do this for all rows of C.
Now to display the cylinder with the specified colours, do something like
figure;
surf(X,Y,Z,C);
colormap(colours);
colorbar;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by