how to use strcmp within the same column

조회 수: 2 (최근 30일)
andrew
andrew 2013년 8월 16일
i am trying to figure out how to use strcmp within the same column
for example: in a column called col 2 which contains a,a,a,b,b,c,c,c,c,d...etc
i would like to use strcmp to do a strcmp for each cell and if they match to print out the values corresponding to that cell.
how do i do this?

답변 (2개)

Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 16일
편집: Azzi Abdelmalek 2013년 8월 16일
s={'a';'a';'a';'b';'b';'c';'c';'c'}
Give an example, what do you want ?
maybe
b='a'
out=s(strcmp(s,b))
  댓글 수: 4
andrew
andrew 2013년 8월 16일
in column you have aaaa,bbbb,cccccc,d,eeee and lets say values for a is 1,2,3,4 if it matches ,concatenate those values corresponding to a in one cell seperated by to make it 1||2||3||4 in one cell
Azzi Abdelmalek
Azzi Abdelmalek 2013년 8월 16일
s={'a';'a';'a';'b';'b';'c';'c';'c'}
idx=num2cell(find(strcmp(s,'a'))');
q=repmat({'||'},1,numel(idx));
f=[idx ; q]
f=f(:)'
f(end)=[]
f=cellfun(@num2str,f,'un',0);
out=horzcat(f{:})

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


Walter Roberson
Walter Roberson 2013년 8월 16일
tf = ismember(TheCell, ValueToSearch);
SelectedValues = AssociatedValues(tf);

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by