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!