Index exceeds matrix dimensions. Please help.
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Here is my code:
disp('Choose one of the following options:');
a1=0;
while(a1~=4)
disp('press 1 for enter sides and shape code:');
disp('press 2 for diplay area:');
disp('press 3 for diplay perimeter:');
disp('press 4 for exit:');
*a1=input('Please Enter Your Selection:');*
if (a1==1)
v1=input('Enter value of side1:');
v2=input('Enter value of side2:');
v3=input('Enter the shape code(t/T for triangle r/R for rectangle:','s');
r1=calcarea(v1,v2,v3);
r2=calcperim(v1,v2,v3);
end
if (a1==2)
disp(['The area is :',num2str(r1)]);
end
if (a1==3)
disp(['The perimeter is :',num2str(r2)]);
end
if (a1==4)
disp('Thank you for using Geometric calculator, Goodbye!');
end
end
The error says: Index exceeds matrix dimensions Error in a1= input('Please enter your selection:'); I have highlighted for convenience.
댓글 수: 0
답변 (1개)
James Tursa
2015년 8월 3일
편집: James Tursa
2015년 8월 3일
0 개 추천
Do you inadvertantly have a variable called "input" in your workspace?
댓글 수: 4
Derrick Edmiston
2015년 8월 3일
James Tursa
2015년 8월 3일
You need to clear that "input" variable from the workspace so that MATLAB can call the "input" function. As it is now, when that line get executed MATLAB thinks you are trying to index into the variable called "input" ... MATLAB is not calling the "input" function which is what you want.
Derrick Edmiston
2015년 8월 3일
James Tursa
2015년 8월 3일
Are you sure? Type the following:
dbstop if error
Then run your code. When it pauses at the error, type "whos" at the command line to see what variables you have.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!