필터 지우기
필터 지우기

how to use for loop?

조회 수: 2 (최근 30일)
aya qassim
aya qassim 2019년 1월 1일
댓글: Star Strider 2019년 1월 2일
if we have an array a= [1,2,3,1,2,3,4,1,2] and second array b=[1,2]
we want to know what is the number of occurrences that b are in a
which means the answer should be 3.
then how to write that using for loop?

채택된 답변

Star Strider
Star Strider 2019년 1월 1일
Unless you absolutely must use a loop, use the strfind (link) function:
a = [1,2,3,1,2,3,4,1,2];
b = [1,2];
c = strfind(a,b);
Result = numel(c)
producing:
Result =
3
  댓글 수: 12
aya qassim
aya qassim 2019년 1월 2일
Thank you, I understood my mistake.
Star Strider
Star Strider 2019년 1월 2일
As always, my pleasure.

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

추가 답변 (0개)

카테고리

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