Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

problems using my custom color map

Asked by Dan on 20 Apr 2013

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.

0 Comments

Dan

Tags

Products

No products are associated with this question.

2 Answers

Answer by per isakson on 20 Apr 2013
Accepted answer

Is

    set(gcf,'Colormap',mycmap)

executed in the base workspace?

5 Comments

Dan on 22 Apr 2013

It works if I execute in the base workspace. Any ideas why it won't work inside of the function? Thanks for the help.

Walter Roberson on 22 Apr 2013
set(gcf, 'Colormap', evalin('base', 'mycmap'))

Are you familiar with the concept of MATLAB "workspaces" ?

Dan on 23 Apr 2013

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!

per isakson
Answer by Image Analyst on 20 Apr 2013

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.

0 Comments

Image Analyst

Contact us