# How to loop both years and months simultaneously?

1 view (last 30 days)
Meenakshy Jyothish on 27 Nov 2020
Answered: Image Analyst on 27 Nov 2020
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?

Image Analyst on 27 Nov 2020
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
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).