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

1 view (last 30 days)
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 Comments
Vittorio
Vittorio on 17 Jul 2014
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.

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 17 Jul 2014
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;

More Answers (0)

Community Treasure Hunt

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

Start Hunting!