Index in position 2 exceeds array bounds?
조회 수: 2 (최근 30일)
이전 댓글 표시
I wrote the at the beginning of my code
jaywalk=zeros(1,n);
then I changed the values in jaywalk
at the end of my code, I wrote
for i=1:n
if jaywalk(1,i)==1
disp(plate(i));
end
end
when I run the code, matlab always tell me 'Index in position 2 exceeds array bounds'
how can i solve the problem?
Any help will be appreciated! Thanks!
답변 (1개)
KSSV
2020년 10월 9일
편집: KSSV
2020년 10월 9일
m = length(jaywalk) ;
n = length(plate) ;
if m ~= n
error("length of jaywalk and plate should be same")
else
for i=1:n
if jaywalk(i)==1
disp(plate(i));
end
end
end
If dimensions of jaywalk and plate are same, you can striaght away use indexing instead of loop.
plate(jaywalk==1) % this will display value of plate when jaywalk == 1
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!