How can I determine the frequency of a text term occurring in a matrix and add this frequency to the matrix?

조회 수: 1 (최근 30일)
I have a matrix of terms that are unique or multiple and I need to count the frequency of each unique term and add this to the matrix so that I can plot it.
An example of my dataset is below.
'CSARDLSGG##YNEQFF' 'CSARDLRPGGAYNEQFF' 'CSALGGGSTYNEQFF' 'CSALGGGSTYNEQFF' 'CSALGGGSTYNEQFF' 'CSAGVRLAGGVYQETQYF' 'CSAGTRK#NTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF'

답변 (2개)

Thomas
Thomas 2012년 12월 6일
a={'CSARDLSGG##YNEQFF' 'CSARDLRPGGAYNEQFF' 'CSALGGGSTYNEQFF' 'CSALGGGSTYNEQFF' 'CSALGGGSTYNEQFF' 'CSAGVRLAGGVYQETQYF' 'CSAGTRK#NTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF' 'CSAGTESNTEAFF'}; % input
out=unique(a); % unique values in a
for ii=1:numel(unique(a))
count(ii)=sum(strcmp(a,out(ii)));
end
unq=out'
count'

Megan
Megan 2012년 12월 6일
How do I apply a scalar?
ii =
1 2 3 4 5 6
Error using strcmp Inputs must be the same size or either one can be a scalar.
  댓글 수: 1
Thomas
Thomas 2012년 12월 6일
I'm assuming you want to find frequency of numeric scalar
a=[1 2 3 4 5 6 3 4 2 3];
out=unique(a);
for ii=1:numel(out)
count(ii)=sum(a==out(ii));
end
fulloutput=[out' count']

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

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by