Filter löschen
Filter löschen

traverse the list of array elements

1 Ansicht (letzte 30 Tage)
pammy
pammy am 13 Mär. 2013
i've code the following for traversing
function traverse
clc;
a=[ 1 2 2 3 3 4 4 4 4]
for i=1:length(a)
if(a(i)==a(i+1))
fprintf('\nmatch\n %d and %d',a(i),a(i+1));
else
fprintf('\nnot a match\n');
end
end
but the following error occurs
Attempted to access a(10); index out of bounds because numel(a)=9.
tell me the way to sort it out...

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 13 Mär. 2013
Use
for i=1:length(a)-1

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by