TA的每日心情 | 开心 2022-1-29 15:03 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
; @2 |: D: o* H( N4 T/ _a=[1 2;1 4;2 3;2 5;3 4;3 7;3 1];
- {+ t+ N! ? D" K5 p%% 方法1
_; t) O7 V; ~ E! Zindex =unique(a(:,1));2 C/ v6 O. C7 P% i
JG=[];
! ?- i3 E2 E3 lfor i =1:length(index)+ ~! {# z4 _7 j4 j) b U- _
JG=[JG;[index(i),mean(a(a(:,1)==index(i),2))]];9 w0 y! u+ V% ]9 E$ ^, T0 {$ w
end
( R% f% v" P2 ]* _%% 方法2利用表的groupsummary 组汇总计算' `( k4 [- E' ^2 J5 i
T=array2table(a, 'VariableNames',{'a1','a2'});6 W! j- L1 X. D: b L
G = groupsummary(T,'a1','mean' );
4 o% F* q# p+ ?; ?6 L) I. htemp=table2array(G);3 T+ r; k" V) k. j* i* Q2 E
out=temp(:,[1,3]); |
|