That figure contains four objects, the fourth one listed is the main axes:
>> fgh = openfig('Resultplot_ID3.fig');
>> fgh.Children
ans =
4x1 graphics array:
Toolbar (plotnavigation)
Menu (&COMSOL)
ColorBar
Axes (Surface: Displacement field, Z component (m))
The main axes has just one child object, which is a patch object:
>> pah = fgh.Children(4).Children;
>> pah.Type
ans =
patch
Patches have several ways of defining their colors based on the axes colormap, explained here:
But the patch in your figure does not use any of those. It uses what the MATLAB documentation calls "truecolor", where the color is explicitly defined using RGB values, and has absolutely nothing to do with the axes colormap.
>> size(pah.CData)
ans =
3 114912 3
You can read more about how that works in the patch documentation, e.g.:
"... how to attach it to a colormap?"
The answer is that you would have to replace the truecolor RGB values in CData and/or FaceVertexCData with indices into the colormap, following the array sizes given in the documentation. Unfortunately MATLAB makes it a bit tricky to get the original colormap data (does anyone know a better way?), but the rest is quite simple:
>> warning off
>> S = load('Resultplot_ID3.fig','-mat');
>> warning on
>> old = S.hgS_070000.children(2).properties.Colormap;
>> image(permute(old,[3,1,2]))
>> [idx,idy] = ismember(pah.FaceVertexCData,old,'rows');
>> all(idx)
ans =
1
>> pah.FaceVertexCData = idy;
>> pah.CDataMapping = 'direct';
Now the patch colors are "attached" to the colormap, exactly as you requested. This only needs to be done once: after that you can simply change the figure colormap to any which has 256 colors, e.g.:
>> colormap(fgh,autumn(256))
Alternatively you could have to update the CData and/or the FaceVertexCdata properties with new RGB values, but this requires updating those arrays everytime you want to change the colormap (i.e. it does not actually "attach" the patch colors to the colormap as you request).
Best Answer