How to loop both years and months simultaneously?
2 次查看(过去 30 天)
显示 更早的评论
I am a beginner in matlab. I am running Tethys and Clara modelling code, and i want to find the mean of each month for 4 years. I am using the "datam" function to do this. I am able to get a plot for 12 months of a particular year.
figure(1);
hold on
X1 = [];
Y1 = [];
X2 = [];
Y2 = [];
for i=1:12
I=(Datam(:,1)==2013)&(Datam(:,2)==i);
ET_obs_2013 = ET_obs(I==1);
ET_obs_mean = mean(ET_obs_2013);
ET_sim_2013 = ET_sim(I==1);
ET_sim_mean = mean(ET_sim_2013);
X1 = [X1,i];
Y1 = [Y1,ET_obs_mean];
X2 = [X2,i];
Y2 = [Y2,ET_sim_mean];
plot(X1,Y1);
plot(X2,Y2);
end
Could you help me check this as well as help with what am looking for?
0 个评论
回答(1 个)
Image Analyst
2020-11-27
Is Datam a function? Looks like it's a 2-D matrix, not a function.
What do the rows and columns of Datam represent?
Attach Datam in a .mat file
save('answers.mat', 'Datam');
then attach answers.mat with the paper clip icon.
If rows are years and columns are months, then just do
monthlyMeans = mean(Datam, 1);
This will give you 12 means, one for each month (Jan-Dec) and averaged over all years (rows).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!