help required using colormap function in matlab

조회 수: 1 (최근 30일)
Ricky
Ricky 2013년 7월 22일
Hello Everyone,
I am using surf function to plot a 2D matrix Z. The matrix has 61 rows and 98 columns. The data varies from 26.5 to 33.5 , and in few places I have some zeros. Till now i was using the default colourmap for plotting my data using surf command. But now I want more control over the colour pattern. I was reading through the documentation of colormap. It says that
"Specify an array of color data that is equal in size to the z- data and is used for indexed colors"
I create a matrix C of same size as Z but I still did not understand what values to put so that I can use the surf function as
figure(),surf(Z,C)

채택된 답변

Daniel Shub
Daniel Shub 2013년 7월 22일
It is not clear what you are trying to do. In the simplest case you might be trying to do
Z = 7*rand(61,98)+26.5;
C = ndgrid(1:size(Z,1), 1:size(Z,2));
but I suspect you are trying to change the colormap
set(gcf, 'ColorMap', [1:64; 64:-1:1; [32:-1:1, 64:-1:33]]'/64)
colorbar
  댓글 수: 4
Ricky
Ricky 2013년 7월 22일
Thanks Daniel for your reply can you please also tell the reason for choosing a 64*3 matrix. The default colormap also uses a 64*3 matrix. I created a color matrix C of size 61*98 what values should I fill in it. Thanks for helping
Daniel Shub
Daniel Shub 2013년 7월 23일
A 61x98 matrix is not a color map. A color map must be Nx3 where the three values in each row represents a RGB values. I chose N to be 64 since 64 different colors tends to be enough to be percieved as visually continuous. If you have discrete data with only 8 values, then you could set N to be 8.
In surf(Z) MATLAB plots a 3D surface with the height of the surface defined by Z. It then uses the color map to assign color such that smaller Z have values from the "bottom" of the color map and larger Z have values from the "top" of the map. What those colors are depends on the color map.
In surf(Z,C) Z is still the height, but MATLAB choses the color from the color map based on C.

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

추가 답변 (1개)

Sean de Wolski
Sean de Wolski 2013년 7월 22일
You can modify it interactively by using the colormapeditor
surf(peaks);
colormapeditor
(Also available through: Edit Menu -> Colormap)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by