saving a newly created colormap
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
Matt Fig
am 26 Mai 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 Kommentare
Walter Roberson
am 26 Mai 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
am 26 Mai 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.
Weitere Antworten (1)
Fangjun Jiang
am 26 Mai 2011
From the help of colormap:
MAP = COLORMAP retrieves the current colormap.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Color and Styling finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!