Setting the range of colormap

I want to set the min and max range of colormap
I want to set the limits of colormap based on the mix and max of values stored in data
data = rand(10,10);
min = min(min(data))
max= max(max(data))
Any suggestions on how this can be done?

Answers (1)

caxis([min(data(:)), max(data(:))]);
See more details

3 Comments

Thanks, I tried your answer
tail = 1:9;
head = 2:10;
G = graph(tail,head);
data = rand(10,10);
caxis([min(data(:)), max(data(:))]);
for k=1:10
clf
G.Nodes.Value = data(:,k);
p = plot(G)
p.Marker = 's';
p.MarkerSize = 7;
p.NodeCData = G.Nodes.Value;
colorbar
%Add plotting options
grid on
title(['t = ',num2str(k)])
view([30 35])
movieVector(k) = getframe;
end
This doesn't seem to work, the colorbar scale changes for every loop
That's because you clear your figure with clf right at the start of the loop! That clears everything including what you set up with caxis(). Don't call clf.
Thank you. I removed clf, even now the color assignd to values change in each iteration

Sign in to comment.

Categories

Products

Release

R2019b

Tags

Asked:

on 20 Jan 2020

Commented:

on 20 Jan 2020

Community Treasure Hunt

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

Start Hunting!