How I can perform a loop in order to calculate multiple means in a matrix based on multiple values?

1 回表示 (過去 30 日間)
Hello Matlab community! I am learning how to perform loops!
I am working with multiple years of meteorological information, and I would like to perform a loop in order to compute the mean by each hour of record, and after that concatenate every result in a single matrix. I have to say that the records are at hour 0, 3, 6, 9, 12, 15, 18 and 21.
I have been working in the next code, but without results:
m3=zeros(8,100);
interval=0:3:21; %these are the hours which the mean would be calculated
for i=1:8
XMINHOUR(i)=XMIN(find(XMIN(:,1) == interval(i)),:);
D_0(i)=XMINHOUR;
m3=mean(D_0);
end
I have attached to the present message the data (variable XMIN)
Thanks in advance for your support!
Miguel
I wanted to ask you

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 8 日
編集済み: Andrei Bobrov 2017 年 11 月 8 日
>> [g,v] = findgroups(XMIN(:,1));
>> out = splitapply(@mean,XMIN,g);
or
[ii,jj] = ndgrid(findgroups(XMIN(:,1)),1:size(XMIN,2));
out = accumarray([ii(:),jj(:)],XMIN(:),[],@mean);
  2 件のコメント
Miguel L
Miguel L 2017 年 11 月 8 日
Hello Andrei!
I really appreciate your help! But I wanna ask you if there is an equivalent of "findgroups" or "splitapply" commands for MATLAB 2011 (my current version).
Best,
Miguel
Andrei Bobrov
Andrei Bobrov 2017 年 11 月 9 日
[~,~,g] = unique(XMIN(:,1));
[ii,jj] = ndgrid(g,1:size(XMIN,2));
out = accumarray([ii(:),jj(:)],XMIN(:),[],@mean);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by