MATLAB Answers

Specific color corresponding to specific data using contourf colormap

2 次查看(过去 30 天)
S Ch
S Ch2021-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 个评论
S Ch
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 个)


S Ch
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:
Data= load(F(i).name);
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