How to assign a different colour for each layer?

Hi everyone,
I am Luca and I have performed an atomistic simulation of epitaxial growth. I have written a specific code for atoms deposition. My result is the following one:
As you can see, this color grading isn't acpetable in order to recognize different layers. How should I do in order to assign a different colour to each layer in order to get a result like the one below?
Thank You!
Aimone Luca

 Accepted Answer

DGM
DGM on 28 Jun 2021
Edited: DGM on 28 Jun 2021
Assuming you're using bar3()
% make some example data
maxlayers = 5;
z = randi(maxlayers,10,10);
h = bar3(z); % the plot
% make a discrete colormap
colormap(jet(maxlayers));
% set cdata to zdata
for k = 1:numel(h)
h(k).CData = h(k).ZData;
h(k).FaceColor = 'interp';
end
% offset clim just a bit to keep tops colored right
caxis([0 maxlayers]+0.001)

More Answers (0)

Products

Release

R2020b

Asked:

on 28 Jun 2021

Commented:

on 30 Jun 2021

Community Treasure Hunt

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

Start Hunting!