saving a newly created colormap

14 visualizaciones (últimos 30 días)
Robert
Robert el 26 de Mayo de 2011
I create a new colormap called "cmapnew". I would like to save it and name it "vortex"so that in the future I can set the current colormap with the statement colormap(vortex). How do I do that? Thanks.

Respuesta aceptada

Matt Fig
Matt Fig el 26 de Mayo de 2011
Two ways you could go about this. First, from the command line:
save mycolormap cmapnew
Then make a new function:
function R = vortex
% Returns my custom colormap
R = load('mycolormap');
R = R.cmapnew;
Note that if you want this to be available from any directory, both the saved .MAT-file and the VORTEX function should be on your search path.
The other approach would be to just hard code the cmapnew array into the vortex function, like:
function cmapnew = vortex
% Returns my custom colormap
cmapnew = [0 0 0.5625
0 0 0.625
0 0 0.6875
0 0 0.75
0 0 0.8125
0 0 0.875
0 0 0.9375];
That way would probably be preferable because then you only have one file to worry about and there is no loading to be done.
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Mayo de 2011
You may wish to use mat2str() to convert the array into a string suitable for pasting in to code.
Also, for consistency with the existing named color maps such as flag and copper, you may wish to declare
function cmapnew = vortex(varargin)
and then either not pay attention to the input arguments or do something different depending on the input. The named maps are not some kind of global variables: they are the names of normal functions, and the Mathworks supplied maps accept an optional parameter which is intended to be the number of entries to be created. For example, copper(81) would create a colormap with 81 entries.
Matt Fig
Matt Fig el 26 de Mayo de 2011
Good suggestion, Walter. One could simply look at the other colormap functions to see how the input args are handled and decide from there.

Iniciar sesión para comentar.

Más respuestas (1)

Fangjun Jiang
Fangjun Jiang el 26 de Mayo de 2011
From the help of colormap:
MAP = COLORMAP retrieves the current colormap.

Categorías

Más información sobre Color and Styling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by