How do I plot a contour plot using my data?

2 次查看(过去 30 天)
clear all;
%SST from Jan 1854-Sep 2021, Precip from Jan 1948-Dec 2020
sst=ncread('sst.mnmean.nc','sst');
time = ncread('sst.mnmean.nc','time');
lat=ncread('sst.mnmean.nc','lat');
lon=ncread('sst.mnmean.nc','lon');
SST1 = sst(:, :, 1753:end);
SST2 = SST1(:,:,1:252);
%SST2 shows 1:252 being the number of months from January 2000 to December 2020. SST2 is 180x89x252 single which is lon by lat by time.
Months = 1:252
Months1 = Months(7:12:252) %I want to find all of the July's of every year so I would have a 180x89x21 since it's 21 July's from 2000-2020
data_jul2 = SST2(:,:,Months1); %This is where the data becomes 180x89x21
monthly_means = mean(data_jul2,3); %I was trying to take the monthly mean of every July and still get the same dimensions but I got a 180x89
data_mat_ac_removed = data_jul2 - monthly_means; %Won't let me plot this 3D into a contour or contourf plot
figure(1);
hold on
contourf(data_mat_ac_removed) %This is the contour plot I tried I also tried contourf(lon,lat,data_mat_ac_removed)
%Both of these I got the error: Error using contourf (line 55), Input arguments must have at most 2 dimensions.
END OF MATLAB CODE!

回答(1 个)

KSSV
KSSV 2021-10-8
Your input is a 3D matrix. contourf needs 2D matrix to plot contours. Input a 2D matrix.
for i = 1:size(data_mat_ac_removed,3)
contourf(data_mat_ac_removed(:,:,i))
drawnow
pause(0.1)
end
  3 个评论
KSSV
KSSV 2021-10-8
I have already showed right? Draw one at a time.
Lauren Pressley
Lauren Pressley 2021-10-8
I keep getting this error from that. Error using contourf (line 55)
Input arguments must have at most 2 dimensions.
Error in New_Script_TIW (line 52)
contourf(data_mat_ac_removed)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by