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

 채택된 답변

David Hill
David Hill 2022년 1월 25일

0 개 추천

Not sure if this the correct guess.
y=sum(strcmp(yourCell,'BB'),2)/size(yourCell,2);

댓글 수: 5

Michael Angeles
Michael Angeles 2022년 1월 25일
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 2022년 1월 25일
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 2022년 1월 28일
Thank you!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2022년 1월 25일

댓글:

2022년 1월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by