saving a newly created colormap

조회 수: 17 (최근 30일)
Robert
Robert 2011년 5월 26일
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.

채택된 답변

Matt Fig
Matt Fig 2011년 5월 26일
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
Walter Roberson
Walter Roberson 2011년 5월 26일
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 2011년 5월 26일
Good suggestion, Walter. One could simply look at the other colormap functions to see how the input args are handled and decide from there.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 5월 26일
From the help of colormap:
MAP = COLORMAP retrieves the current colormap.

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by