How do I create a colormap?

조회 수: 2 (최근 30일)
Theo Kooijman
Theo Kooijman 2014년 1월 29일
답변: Image Analyst 2014년 1월 29일
I've been having problems creating a colormap in the Staff version of Matlab (Matlab R2013b). I want to create a colormap of the type "jet", so I typed in the Command Window:
myColorMap = jet(256);
colormap(myColorMap);
colorbar
However, when I press enter, a window (called "Figure 1") pops up with a colormap, but with no picture in it. I've imported the picture (filename: Picture1Edit.jpg) into the program, I can see it in the sidebar "Current folder" left of my Command Window, so I know it's definetely there. Could anyone help me creating this colormap?

답변 (2개)

Bjorn Gustavsson
Bjorn Gustavsson 2014년 1월 29일
That's the way you create a colormap. The colorbar command forces the creation of an axes, that forces the creation of a figure (unless the figure and an axes already exists). To display the image you'll have to use some of the image display-functions: imshow, image, imagesc; or even surf/pcolor if you want some more complex warping of the image. Then you can put a colorbar on the side of those displays.
HTH

Image Analyst
Image Analyst 2014년 1월 29일
Try this:
% Get full file name.
baseFileName = 'Picture1Edit.jpg';
folder = pwd; % Current folder
% Display if it exists, warn and exit if not.
if exist(fullFileName, 'file')
grayImage = imread(fullFileName);
imshow(grayImage);
else
message = sprintf('Error: %s not found', fullFileName);
uiwait(warndlg(message));
return;
end
% Apply colormap.
myColorMap = jet(256);
colormap(myColorMap);
colorbar

카테고리

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