How to manually define value range in colormap

Hi. I'm trying to create an image from a txt file which contains X, Y, Z values, in which Z is the pixel intensity. (thanks to this thread :) -> https://kr.mathworks.com/matlabcentral/answers/339147-how-to-create-an-image-in-matlab-from-txt-file. I'm only a beginner to Matlab, and my questions may sound a bit silly. My apology!
I plotted as below:
1) But I'd like to give a certain range a certain color as the image below (the image was retrieved from Hegedüs et al. 2007 Applied Optics):
2) Or in a greyscale range below (from Barta et al. 2014 Applied Optics):
I'm so sorry to ask too much, but could anyone help me out please?
Thank you in advance.

 채택된 답변

KSSV
KSSV 2018년 11월 15일

2 개 추천

Read about caxis it will help you to define the range in the colormap.

댓글 수: 4

EcoBase
EcoBase 2018년 11월 16일
Hi, thank you for the advice! I looked it up.
But I'm still having a problem. As I understood, caxis only allows to set minimum or maximum range. Values inbetween those two are, again, linearly mapped.
I'd like to set intervals manually and also to give a certain values in a range a particular color.
For example (as shown in the figure I previously uploaded),
values between 0-2 : purple
values between 2-4 : pink
values between 4-6 : yellow
values between 6-8 : green
values between 8-10 : red
values between 10-12 : skyblue
values between 12-14 : orange
values between 14-16 : light green
and values between 16 to over 100 : grayscale
I attached my txt file for your reference.
I really appreciate your help.
YOu can create your required colormap with the values you have. Let A be your data.
%% Colorbar ranges
crange = [0 2; 2 4; 4 6; 6 8; 8 10;10 12;12 14; 14 16; 16 inf] ;
cmap = rand(size(crange,1),3) ; % specify your colors in RGB here..I have used random
%% Arrange the colors range
colors = zeros(size(A));
for i = 1:size(crange,1)
colors(A > crange(i,1) & A<=crange(i,2)) = crange(i,2);
end
surf(X,Y,A, colors) ; shading interp ;
view(2)
colorbar
colormap(cmap)
EcoBase
EcoBase 2018년 11월 16일
Thank you so much! I can't express my gratitude enough. I tried with your code, and it worked. Thank you!
By the way, I'd like to colors in grayscale to values greater than 16. Would you please teach me how to do that as well?
Thank you and I'm so sorry to bother you.
KSSV
KSSV 2018년 11월 16일
What happens when you specify black color in RGB code?

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

추가 답변 (0개)

카테고리

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

제품

릴리스

R2018b

태그

질문:

2018년 11월 15일

댓글:

2018년 11월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by