Filter löschen
Filter löschen

how to use for loop?

2 Ansichten (letzte 30 Tage)
aya qassim
aya qassim am 1 Jan. 2019
Kommentiert: Star Strider am 2 Jan. 2019
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?

Akzeptierte Antwort

Star Strider
Star Strider am 1 Jan. 2019
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 Kommentare
aya qassim
aya qassim am 2 Jan. 2019
Thank you, I understood my mistake.
Star Strider
Star Strider am 2 Jan. 2019
As always, my pleasure.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by