Index exceeds matrix dimensions while using a for loop
Ältere Kommentare anzeigen
I tried to make a simple program to find a specific set of numbers, but when I run it, it says "Index exceeds matrix dimensions". The line that causes an issue is "if(r(i+1)==2)"
does anyone know what the problem could be? I don't see it. r is a 10000x1 matrix, so I believe the dimensions are alright.
x=0
while (x==0)
n=10000
r = randi([0 9],n,1);
for i=1:n
if(r(i)==1)
if(r(i+1)==2)
if(r(i+2)==3)
if(r(i+3)==4)
if(r(i+4)==5)
if(r(i+5)==6)
if(r(i+6)==7)
if(r(i+7)==8)
if(r(i+8)==9)
display('found')
display(i)
x=1
end
end
end
end
end
end
end
end
end
end
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!