How can I save a custom color palette and use it again in Matlab?

I have created a color picker that is similar to the ROOM-BLI color code for BLOCK-BL, done by hand in the colormap editor see here .

However, I cannot save this as a color code. I have tried different commands like

mycmap = get(gcf,'colormap')

      

I read that as of Matlab 2015 one needs to use gca, but that gives an error.

Error when using matlab.graphics.axis.Axes / get There is no colormap property in the Axes class.

When I try to use mycmap saved for another drawing, it ignores all modifications and uses the base color picker.

Thanks for the help. How can I save it and use it as another color map in any shape I want?

+3


source to share


1 answer


The definition of color maps is deeply hidden within a shape class that is not available. Therefore you cannot save your flower card "with a name" in Matlab and access it like a normal color map. But colormap is nothing more than a Yx3 matrix that you can save to disk.

%// custom colormap
n = 50;               %// number of colors
R = linspace(1,0,n);  %// Red from 1 to 0
B = linspace(0,1,n);  %// Blue from 0 to 1
G = zeros(size(R));   %// Green all zero
myCustomColormap = [R(:), G(:), B(:)];

%// save colormap on disk
save('myCustomColormap','myCustomColormap');

%// clear for explanation purposes
clear 
%%%%%%%%%%%%%%%%%%%

%// load colormap saved on disk
load myCustomColormap

%// assign colormap
colormap( myCustomColormap ); 

      




You used the colormap editor to create your color map. Once you've applied it, use the following code to get the required matrix for future reference:

myCustomColormap = colormap(gca)
save('myCustomColormap','myCustomColormap');

      

If you want the colored folder to be public for all your functions, no matter where you add it to the Matlab search path .

+2


source







All Articles