For Loop to read rows on a cell array

need help on the following...
key = 'BB';
data = cell(1,24);
data = {'BB'};
for i = size(data);
%compare key to each data on each column
if key = data;
%count number of elements that matches with key
counts = count how many times BB occurs
%number of elements that match divided by size of data
occurrence = counts/side of data

 Respuesta aceptada

David Hill
David Hill el 25 de En. de 2022
Not sure if this the correct guess.
y=sum(strcmp(yourCell,'BB'),2)/size(yourCell,2);

5 comentarios

Michael Angeles
Michael Angeles el 25 de En. de 2022
I rewrote the question...maybe that will help
No loop necessary.
yourCell={'BB','AC','D','EF','BB','CD','BB','NF','BB','BB','AB';...
'BB','AC','D','BB','BB','CD','BB','BB','BB','BB','AB'};
key='BB';
y=sum(strcmp(yourCell,key),2)/size(yourCell,2);
Michael Angeles
Michael Angeles el 25 de En. de 2022
one more question: how do I count the number of strings that do not match? Thank you so much!
notMatching=sum(~strcmp(yourCell,'BB'),2);
Michael Angeles
Michael Angeles el 28 de En. de 2022
Thank you!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 25 de En. de 2022

Comentada:

el 28 de En. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by