The following code is showing me matrix dimension error....please help,

clc
clear all
close all
figure(1)
axis([1 12 1 12])
x=1:8;
for i=1:8
line([x(i) x(i+1)],[3 4],'linewidth',2,'color','black')
end

 채택된 답변

Birdman
Birdman 2018년 3월 25일
편집: Birdman 2018년 3월 25일
When i=8, you try to reach 9th element of x at this line:
line([x(i) x(i+1)],[3 4],'linewidth',2,'color','black')
when x(i+1) is operated. You have 8 element in your x array, so fix that.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 3월 25일

0 개 추천

You initialize x=1:8 so the last entry in x is x(8)
You loop for i=1:8, and inside your loop you refer to x(i) and x(i+1) . When i = 8, that is x(8) and x(8+1) = x(9). However, there is no x(9) in your array.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2018년 3월 25일

댓글:

2018년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by