How do I create a colormap?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (2)
Bjorn Gustavsson
le 29 Jan 2014
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
0 commentaires
Image Analyst
le 29 Jan 2014
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
0 commentaires
Voir également
Catégories
En savoir plus sur Color and Styling dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!