Using for loop to count how many times a content appears in a cell array?

조회 수: 1 (최근 30일)
Hello MATLAB Experts,
Suppose I have a cell arr arr
I want to use for loop to get the pattern of each different words in the cell and Sort like this form:
Descending => Alphabetical order if the patern of 2 words are equal
aa: 3
cs: 2
avb: 1
ef: 1
arr = {'aa';'avb';'cs';'aa';'ef';'aa';'cs'}
%Then I use for loop to find the pattern of each cell
for i = 1 : length(arr)
list = find(strcmp(arr,arr(i)))
end
%The list appears at both 'aa' 1st position and 'aa' 4th position. How can I get rid one of them??
Thank you for your help!!!

채택된 답변

madhan ravi
madhan ravi 2019년 6월 21일
편집: madhan ravi 2019년 6월 21일
T=cell2table(arr);
Wanted = sortrows(varfun(@sum,T,'GroupingVariables','arr',...
'OutputFormat','table'),2,'descend')
% For versions since 2018b
Wanted = sortrows(groupsummary(T,{'arr'}),2,'descend')
  댓글 수: 2
Fat Man
Fat Man 2019년 6월 21일
Thank you.
Just one more question. Is there anyway that I can get rid of one repeat content as my code above???
madhan ravi
madhan ravi 2019년 6월 21일
편집: madhan ravi 2019년 6월 21일
Honestly, what your doing is waste of time. Btw what release are you using? When you ask a question mention what release your using forehand don’t let the answerers guess!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by