Assign only 2 colors in a surf plot, one color for values smaller 27 and one for all bigger

Hello, if somebody could help, it would really great. I want to have a plot using the surf command with one color for values below 27 and one other for values above. Is it possible to do it easily ? I have checked the options on colormap but I dont know what to change.
At this stage the "surf" is perfectly working with values for z going from 3.6 to 2431 and therefore with colors going from blue to red.
Best regards and thank you for the answer.
x = reshape(untitled(:,1),12,9)';
y = reshape(untitled(:,2),12,9)';
z = reshape(untitled(:,3),12,9)';
%z =20*log10(reshape(untitled(:,3),12,9)');
figure(1) surf(x,y,z)

 채택된 답변

Try this, where I make it red above 27 and cyan below 27:
% Generate sample data in the rand 1.3 to 45.3
z = 3*(peaks(100)+7);
% Make colors be red above 27, and cyan below 27.
redChannel = z > 27;
greenChannel = z < 27;
blueChannel = greenChannel;
% Make the RGB image.
colors = double(cat(3, redChannel, greenChannel, blueChannel));
% Plot the surface with those colors.
surf(z, colors);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

댓글 수: 1

Hello, great, thank you for your answer! It is what I was searching for. Best regards.

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

추가 답변 (1개)

Arthur Allen
Arthur Allen 2013년 5월 20일
Answer #1, works well for simple colors divisions, and can be expanded to additional bands with 'ifelse' statements. However, if you are trying to use colormap and colormapeditor the Matlab Help skips a really important detail. That is you have to decide up front, the number of colors in colormap that is right for your display. In your example this would be two, setting
>> Julian_colormap = colormap(jet(2)); >> colormapeditor
Once in ‘Colormap Editor’ you would set Color data min: 0.0 Color data max: 54.0
Following the example in Colormapeditor, click on bars to change color to suit, (red and green in your case), and also click on bars to see Index 1 starts a 0E0 and Index 2 starts at 27.0
Now, if you want 10 colors, use:
>> Julian10_colormap = colormap(jet(10));
And use colormapeditor, follow colormapeditor HELP example to modify, and ‘save’ and ‘load’ your custom Julian10_colormap for later use.

카테고리

도움말 센터File Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

질문:

2013년 5월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by