# How to set scale range for a contour?

14 views (last 30 days)
Antonin on 12 Apr 2024
Answered: Gautam on 20 May 2024
Hi,
I've been trying to set a scal for a contourf program but I've been quit unsucessfull.
This is my code :
%% Plot EEM
% Make sure that the code found the CSV
if isempty(fileList)
error('Aucun fichier CSV trouvé dans le dossier spécifié.');
end
% Counter for the number of CSV files processed
counter = 0;
% Loop to process each CSV file
for i = 1:min(length(fileList), 6)
% Import CSV file as a matrix
filePath = fullfile(folderPath, fileList(i).name);
% Create a contourf plot
figure;
X=250:2:550;
Y=250:5:550;
contourf(X,Y,data);
% Add a color bar
colorbar;
colormap(redwhiteblue(-1, 1));
h = colorbar;
% Specify the scale of the color bar
clim([0 1]);
The main problem is with the
% Create a contourf plot
figure;
X=250:2:550;
Y=250:5:550;
contourf(X,Y,data);
I create X and Y to set a scale that goes from 250 to 550 with a different tick.
I always get this error :
Error using contourf
The size of X must match the size of Z or the number of columns of Z.
Error in plot_EEM_post_treatment (line 35)
contourf(X,Y,data);
Isn't it possible to get rid of this problem ?

SAI SRUJAN on 1 May 2024
Hi Antonin,
I understand that you are facing an issue with the 'contourf' function in MATLAB is due to the dimensions of 'X' and 'Y' vectors not matching up with the dimensions of the 'data' matrix. For 'contourf' to work correctly, the length of 'X' must be equal to the number of columns in 'data', and the length of 'Y' must be equal to the number of rows in 'data'.
Please go through the following code sample to proceed further,
[dataRows, dataCols] = size(data);
X = linspace(250, 550, dataCols); % Adjust X to match the number of columns in 'data'
Y = linspace(250, 550, dataRows); % Adjust Y to match the number of rows in 'data'
contourf(X, Y, data);
For a comprehensive understanding of the 'contourf' MATLAB function, please go through the following documentation.
I hope this helps!

Gautam on 20 May 2024
Hello, Antonin
The code gives you an error because the size of the vectors “X” and “Y” doesn’t match the size of “data”. The function “contourf” expects the inputs “X” and “Y” to be matrices of the same size as the “data” input.
You can create meshgrids of “X” and “Y” that matches the size of the “data” matrix to resolve the error.
Please refer to the following MathWorks documentation page on “contourf” function for more details

### Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

R2023a

### Community Treasure Hunt

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

Start Hunting!