How to set scale range for a contour?
21 次查看(过去 30 天)
显示 更早的评论
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);
data = readmatrix(filePath);
% 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 ?
0 个评论
回答(2 个)
SAI SRUJAN
2024-5-1
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,
% Assuming 'data' is already loaded
[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!
0 个评论
Gautam
2024-5-20
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Oceanography and Hydrology 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!