Extracting the mean of 2nd column based on unique 1st column values.
1 回表示 (過去 30 日間)
古いコメントを表示
I have this vector,
1 22.6391
1 22.6357
1 22.6338
1.5 22.1159
1.5 22.1056
1.5 22.0950
1.5 22.08820
2 22.11870
2 22.11100
2 22.10280
2 22.09650
And I want a mean of the 2nd column values based on the unique 1st column values. Like,
1 22.63
1.5 22.10
2 22.10
I have tried using tmp = [unique( SINR_tmp(:,1) ),accumarray( SINR_tmp(:,1), SINR_tmp(:,2), [], @mean )];
but this gives unique values only when 1st column has integer values. But I need to include the floating values too in the 1st column.
I have also tried using the function unique() in various ways. But could not succeed in getting the desired result.
I would really appreciate any kind of help on this.
Thank you,
Rahul Singh Gulia
0 件のコメント
採用された回答
Voss
2022 年 1 月 27 日
Here are two similar methods that produce identical results:
SINR_tmp = [ ...
1 22.6391; ...
1 22.6357; ...
1 22.6338; ...
1.5 22.1159; ...
1.5 22.1056; ...
1.5 22.0950; ...
1.5 22.08820; ...
2 22.11870; ...
2 22.11100; ...
2 22.10280; ...
2 22.09650; ...
];
% Method 1:
uS = unique(SINR_tmp(:,1));
uS(:,2) = NaN;
for ii = 1:size(uS,1)
uS(ii,2) = mean(SINR_tmp(SINR_tmp(:,1) == uS(ii),2));
end
disp(uS);
% Method 2:
[uS,~,jj] = unique(SINR_tmp(:,1));
uS(:,2) = NaN;
for ii = 1:size(uS,1)
uS(ii,2) = mean(SINR_tmp(jj == ii,2));
end
disp(uS);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Fourier Analysis and Filtering についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!