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 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