I have:
Temperature profiles array for 5 days. such that, temp(heigth,day). however, there are multiple profile in some days which makes the number of profile equal 11.
size of temp = (3650 by 11)
size of day = (1 by 11)
day=[1,1,1,2,2,3,3,3,4,4,5].
I want to:
average temperature for every similar days
such that:
dailyday=[1,2,3,4,5]
temp=(3650 by 5)

 採用された回答

madhan ravi
madhan ravi 2019 年 5 月 17 日

1 投票

splitapply(@(x) mean(x,2),Temp,findgroups(Day))

5 件のコメント

madhan ravi
madhan ravi 2019 年 5 月 17 日
編集済み: madhan ravi 2019 年 5 月 17 日
Prior to 2015b:
dailyday=unique(Day)
M=mat2cell(Temp,size(Temp,1),histc(Day,dailyday));
temp=cell2mat(cellfun(@(x) mean(x,2), M, 'un',0))
Kafayat Olayinka
Kafayat Olayinka 2019 年 5 月 17 日
I recieved this message while running the second line.
Error using mat2cell (line 89)
Input arguments, D1 through D2, must sum to each dimension of the input matrix size
Kafayat Olayinka
Kafayat Olayinka 2019 年 5 月 17 日
Recieved this error while compiling the first code with splitapply*
Error using splitapply (line 132)
The function '@(x)mean(x,2)' returned a non-scalar value when applied to the 5th group of data.
To compute nonscalar values for each group, create an anonymous function to return each value in a scalar
cell:
@(x){mean(x,2)}
madhan ravi
madhan ravi 2019 年 5 月 17 日
編集済み: madhan ravi 2019 年 5 月 17 日
C=splitapply(@(x) {mean(x,2)},Temp,findgroups(Day));
[C{:}]
%or
[~,~,c]=unique(Day);
C = accumarray(c,1:size(Temp,2),[],@(x){mean(Temp(:,x),2)});
[C{:}]
Kafayat Olayinka
Kafayat Olayinka 2019 年 5 月 17 日
Worked perfectly. Thank you.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 5 月 17 日

0 投票

[mean(temp(:,1:3),2), mean(temp(:,4:5)), mean(temp(:,6:8)), mean(temp(:,9:10)), temp(:,11)]

1 件のコメント

Kafayat Olayinka
Kafayat Olayinka 2019 年 5 月 17 日
Thanks. How should I write the loop assuming Days are more than 5 days and each day may have multiple temperature profiles. How should I average each temp profile per day?

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by