How to get statistical summary
이전 댓글 표시
Hi,
I have below cell array,
Step 34
Step 56
Double 23
Stop 123
I want to get the summation and count of each category:
Desired output:
Step 90 2
Double 23 1
Stop 123 1
Continue 0 0
Here in the above example, no continue, but in some of my cases it exists. So for each scenario, I want to get the summation & count of: Step Double Stop Continue
채택된 답변
추가 답변 (1개)
Kevin Chng
2018년 10월 16일
편집: Kevin Chng
2018년 10월 16일
A = ["Step" "Step" "Double" "Stop" "Continue"];
B = [ 34 56 23 123 0]
[c,~,d] = unique(A);
out = [c',accumarray(d,B),countcats(categorical(A))']
댓글 수: 2
Mekala balaji
2018년 10월 16일
Kevin Chng
2018년 10월 16일
편집: Kevin Chng
2018년 10월 16일
change to
out = table(c',accumarray(d,B),[zeros(numel(A(B==0)))';countcats(categorical(A(B>0)))'])
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!