Updating CData of subimage unwantedly resets its colormap
5 views (last 30 days)
Show older comments
Hi. Below is a class which manages 2 subimages in 1 figure. Both have different colormaps. However, as soon as i try to update the CData of either subimage, its colormap also gets reset. This is not what I want. Instead, I want the colormap to remain the same. Besides redrawing the entire figure, I'm unsure how.
classdef ImageTest
properties
image_1;
image_2;
end
methods
function obj = ImageTest()
figure(1);
subplot(1,2,1);
obj.image_1 = subimage(rand(5)*100, autumn);
subplot(1,2,2);
obj.image_2 = subimage(rand(5)*100, gray);
end
function obj = Change(obj)
set(obj.image_1, 'cdata', rand(5)*100);
drawnow;
end
end
end
0 Comments
Accepted Answer
per isakson
on 6 Apr 2014
Edited: per isakson
on 6 Apr 2014
Matlab uses index-data in combination with a colormap or true color data, which does not depend on a colormap. See:
That's the best description I find.
.
The first input argument of ind2rgb and ind2rgb8 is supposed to be a matrix of indices (into the colormap), i.e. a matrix of whole numbers. IMO: It's a side effect of calling a mex-function that makes ind2rgb8 work in your case. The error handling doesn't gracefully cover this. Inserting round makes ind2rgb work.
set(obj.image_1, 'cdata', ind2rgb( round(rand(5)*100), autumn ) );
0 Comments
More Answers (1)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!