I have a table where each entry is a word/sentence. How do I count how many times a word shows up?

조회 수: 3 (최근 30일)
I have a table T that is derived from a poll taken online. As an example one column I have 'male', female', 'other' and in another column I have if the prefer 'dog' or 'cat'. My question is how do I count how many times someone answered 'male' and how many times someone answered 'female' etc. So that I can put the results into a pie graph.
gender = [{'male'}; {'female'}; {'male'}; {'male'}]
dogorcat = [{'dog'}; {'cat'}; {'dog'}; {'dog'}]
T = table(gender,dogorcat);

답변 (1개)

Ive J
Ive J 2021년 9월 9일
Check out groupsummary:
gender = {'male', 'female', 'male', 'male'}.';
dogorcat = {'dog', 'cat', 'dog', 'dog'}.';
T = table(gender,dogorcat);
genderT = groupsummary(T, 'gender')
genderT = 2×2 table
gender GroupCount __________ __________ {'female'} 1 {'male' } 3

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by