how to use strcmp within the same column
Mostrar comentarios más antiguos
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?
Respuestas (2)
Azzi Abdelmalek
el 16 de Ag. de 2013
Editada: Azzi Abdelmalek
el 16 de Ag. de 2013
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 comentarios
andrew
el 16 de Ag. de 2013
Editada: Azzi Abdelmalek
el 16 de Ag. de 2013
Azzi Abdelmalek
el 16 de Ag. de 2013
This is not clear, give an example with data
andrew
el 16 de Ag. de 2013
Azzi Abdelmalek
el 16 de Ag. de 2013
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
el 16 de Ag. de 2013
tf = ismember(TheCell, ValueToSearch);
SelectedValues = AssociatedValues(tf);
Categorías
Más información sobre MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!