how to use strcmp within the same column

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 日

0 投票

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 日
編集済み: Azzi Abdelmalek 2013 年 8 月 16 日
well i have the following code:
s= data2.REGIMEN(1);
n=0;
for i=2:length(data2)
%
if strcmp (data2.SUBJECT,data2.SUBJECT{i})
s=strcat(s,['||' char(data2.REGIMEN(i))]);
n=n+1;
% else
% s=data2.REGIMEN{i};
end
end
just can't figure out how to use the strcmp feature
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 16 日
This is not clear, give an example with data
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 日

0 投票

tf = ismember(TheCell, ValueToSearch);
SelectedValues = AssociatedValues(tf);

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2013 年 8 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by