# Specific color corresponding to specific data using contourf colormap

조회 수: 4(최근 30일)
S Ch 2021년 5월 12일
편집: S Ch 2021년 6월 25일
Hello,
I would like to know if we can give a specific color to a specific data and plot them on Matlab ?
For example, I have a 3000x3000 matrix with x and y axis, I need to plot a range of data in a specific color.
I've already generated the map with, but the colors are random
this is my code :
A= data;
figure;
[v,x] = meshgrid(v,x);
contourf(v,x,A)
figure;
%colourRGB = hsv(jet);
c=colormap(jet); %jet
L=[0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1];
[cdd hc]=contourf(v,x,A,[-0.01 L]);
Recolor_contourf(hc,c,L,'vert');
I want for example if A(x,y)==0.07 the colormap will be green ...
I can give more details.
Kind regards,
S.C
##### 댓글 수: 6표시숨기기 이전 댓글 수: 5
S Ch 2021년 5월 17일
Hello,
thank you for all your answers, I'll check them later, I switched to another project with a deadline,
The best thing to confirm your response is to try them, so I don't want to accept, give me a moment, please.
Thanks again.

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

### 답변(2개)

Perhaps @Kelly Kearney's contourfcmap is what you need?
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

S Ch 2021년 6월 25일
편집: S Ch 2021년 6월 25일
Hello,
Thank you @DGM, @J. Alex Lee and @Chad Greene for your answers! It was great to use these methods and it is what I need!
I used the contourfcmap and I directly chose the number of levels I want, unfortunately I'm struggling to do a loop of 100 images using this method ! anyone can help me please?
To explain the problem, I have 100 matrices in a folder (each matrix is an image that I want to contourfmap) and after that save them in a folder as images with the colors I chose in contourfmap. Is this possible ?
This is my code:
for i = 1:N
%names is the char name of all matrices
if i < 10
names(i,:) = strcat("X_t0000",string(i),".mat");
else
names(i,:) = strcat("X_t000",string(i),".mat");
end
% A = eval(names);%(i,:)) ;
%After that I didn't know how to use names so I change to this follows:
z=Data.data; %iside each matrix there is matrix named 'data'
h1 = contourfcmap(v,x,z,[0.1 0.33],jet(1),[.1 .1 .1], [.9 .9 .9], 'eastoutside')
d = h1.c
l=h1.h
export_fig(fullfile(Folder, sprintf('%05d.png', i)))
%%% Here I had only one image appeared I think the last one.
% imwrite(d,fullfile(Folder, sprintf('%05d.png', i)))
% A = cat(3,names); %Here I wanted to concatenate the 100 matrices into
% one like 2048x2048x100 but I didn't succed
end
If it isn't clear please tell me to explain more. Thank you in advance.
S.C

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

### Community Treasure Hunt

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

Start Hunting!

Translated by