필터 지우기
필터 지우기

traverse the list of array elements

조회 수: 1 (최근 30일)
pammy
pammy 2013년 3월 13일
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...

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 3월 13일
Use
for i=1:length(a)-1

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by