1 5
2 7
3 9
1 9
2 7
3 9
if column 1 is month how to get the mean of January only which is 5 and 9 then feb which is 7 and 7 mean then march 9 and 9 mean
Thanks in advance

 採用された回答

Paul Hoffrichter
Paul Hoffrichter 2021 年 2 月 22 日

0 投票

M = [ ...
1 5
2 7
3 9
1 9
2 7
3 9
];
T = array2table( M, ...
'VariableNames',{'Month','Rainfall'});
disp('Table');
disp(T)
Tmean = varfun(@mean,T,'InputVariables','Rainfall',...
'GroupingVariables','Month');
disp('Mean of Rainfall by Month')
disp(Tmean)
Output
Table
Month Rainfall
_____ ________
1 5
2 7
3 9
1 9
2 7
3 9
Mean of Rainfall by Month
Month GroupCount mean_Rainfall
_____ __________ _____________
1 2 7
2 2 7
3 2 9

5 件のコメント

Hazem Mahmoud
Hazem Mahmoud 2021 年 2 月 22 日
Thank you Paul. perfect discription of variables
Paul Hoffrichter
Paul Hoffrichter 2021 年 2 月 22 日
You're very welcom, Hazem.
Hazem Mahmoud
Hazem Mahmoud 2021 年 2 月 22 日
編集済み: Hazem Mahmoud 2021 年 2 月 22 日
I am trying to plot them x,y
plot(Tmean(:,1),Tmean(:,3),'b-') is not working
please advice
Paul Hoffrichter
Paul Hoffrichter 2021 年 2 月 22 日
Is this what you want?
plot(Tmean.Month, Tmean.mean_Rainfall, '-bo')
Hazem Mahmoud
Hazem Mahmoud 2021 年 2 月 22 日
Yes, Sir. It worked :)
Thank you so much

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

その他の回答 (0 件)

カテゴリ

製品

リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by