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 Center および File ExchangeColor and Styling についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by