how to use for loop?

2 次查看(过去 30 天)
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