Control scale and colors in temperature contour

im using this code to plot temperature contour from excel files, the issue is im doing it for different excel files so i want to have a unified scale and not auto scale because range is not the same for my files.so for example i want the range to be always between 28 and 36 . Also i would like to know if i can change/control the colors of the contour.
This is the code im using and ill also attach an example of the excel file im taking data from.
data = readmatrix('a.xlsx');
[m,n] = size(data);
% scale the x / y axis
% create x axis matching range : 0 to 220
% create y axis matching range : 0 to 50
x = (0:n-1)/(n-1)*220;
y = (0:m-1)/(m-1)*50;
% 2D data smoothing
matrixOut = smooth2a(data,10,10);
% or
% matrixOut = smoothn(data,50,'robust');
contourf(x,y,matrixOut);
colorbar('vert')

 Accepted Answer

You need to read in all the files first to determine the overall max and min. Then you can create a colormap and apply if to the files as you read them in again.

6 Comments

if i know my max and my min, how can i create a colormap ?
You create a colormap like this:
cMap = turbo(256); % or hot() or whatever one you want.
Then after you plot/display each plot you can apply the colormap and use clim or caxis to set what value corresponds to the bottom of the colormap and what value corresponds to the top of the colormap
colormap(cMap);
clim([overallMin, overallMax]);
You have to do that for each axes you're putting contours into.
can you explain more how can i create my own colormap and connect each color with a value. i want it to range from lowest value (red) in this order ( red, green blue) with each color to change from light to dark then change.
@Ahmad study this little demo:
% Make random data a ramp between 200 and 1500
ramp1d = linspace(200, 1500, 50);
data = repmat(ramp1d, 50, 1); % Replicate to make it a 2-D image of a ramp.
% Display it in gray scale in the upper plot.
h1 = subplot(3, 1, 1);
imshow(data, []);
colorbar;
title('Gray Scale');
% Find out what the current limits are
lims1 = clim(h1)
lims1 = 1×2
200 1500
% Display it in the upper plot.
h2 = subplot(3, 1, 2);
imshow(data, []);
title('Colors span entire scale');
% Make a "jet" colorbar with 256 distinct color levels/shades.
cMap = flipud(jet(256));
% Apply the colormap
colormap(h2, cMap);
colorbar; % Show the bar beside the image.
% Find out what the current limits are
lims2 = clim(h2)
lims2 = 1×2
200 1500
% Display it in the lower plot.
h3 = subplot(3, 1, 3);
imshow(data, []);
title('Colors span from 700 to 1000');
% Apply the colormap
colormap(h3, cMap);
colorbar; % Show the bar beside the image.
% Make the colormap apply just between 700 and 1000.
clim([700, 1000]);
% Find out what the current limits are
lims3 = clim(h3)
lims3 = 1×2
700 1000
Thanks for your help. I created my own colormap and it works fine
Glad it's working for you. If this, or another, Answer solves your original question best, then could you please click the "Accept this answer" link to award the best answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!