problems using my custom color map

Hi, I made a custom colormap (size = 15 x 3) and now I am trying to use it but it is not working. Here is the code:
...plotting code
set(gcf,'Colormap',mycmap)
And then I get this error:
Undefined function or variable 'mycmap'.
The mycmap variable is loaded into my workspace. Any help is appreciated.
Thanks, Dan.

 채택된 답변

per isakson
per isakson 2013년 4월 20일

0 개 추천

Is
set(gcf,'Colormap',mycmap)
executed in the base workspace?

댓글 수: 5

Dan
Dan 2013년 4월 20일
It is executed inside of a plotting function I created.
per isakson
per isakson 2013년 4월 20일
편집: per isakson 2013년 4월 20일
Then you have two alternatives (at least)
  1. pass mycmap into the plotting function as an input argument
  2. run the function
colormap( mycmap );
or
set(gcf,'Colormap',mycmap)
in the base workspace
Dan
Dan 2013년 4월 22일
It works if I execute in the base workspace. Any ideas why it won't work inside of the function? Thanks for the help.
set(gcf, 'Colormap', evalin('base', 'mycmap'))
Are you familiar with the concept of MATLAB "workspaces" ?
Dan
Dan 2013년 4월 23일
Yes, but I just read up on the documentation to clarify things. I guess need to define the colormap inside of the function, or use your option Walter. Thanks for the help and advice!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 4월 20일

0 개 추천

You can try using the colormap() function instead. Does this work for you?
grayImage = imread('cameraman.tif');
image(grayImage);
mycmap = jet(15);
% set(gcf,'Colormap',mycmap)
colormap(mycmap);
colorbar
Apparently you did not specify mycmap like you thought. Put this line right before your call to set():
whos mycmap
If it says it's undefined, then it is undefined, not 15 by 3 like you thought.

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

질문:

Dan
2013년 4월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by