Mean of a repeating numbers corresponding values
1 次查看(过去 30 天)
显示 更早的评论
I have a matrix like [ 10 40; 10 60 ;10 90; 14 10; 14 20; 14 30; 14 40] i want to calculate the mean of the repeating numbers corresponding values like repeating 10 corresponding values are 40 60 90 so the mean is 190/3 and similarly the 14 corresponding values are 10 ,20,30,40 so the mean is 100/4. How can i do this ?
0 个评论
采纳的回答
Simon Chan
2022-3-24
Use function groupsummary:
A = [ 10 40; 10 60 ;10 90; 14 10; 14 20; 14 30; 14 40];
T = table(A(:,1),A(:,2),'VariableName',{'Item','Value'});
S = groupsummary(T,'Item','mean')
4 个评论
Simon Chan
2022-3-24
A = [ 10 40; 10 60 ;10 90; 14 10; 14 20; 14 30; 14 40];
Item = A(:,1);
Value = A(:,2);
[UItem,~] = unique(Item);
meanValue = arrayfun(@(x) mean(Value(ismember(Item,x))),UItem);
result = [UItem, meanValue]
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!