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.

Answers (1)

James Tursa
James Tursa on 3 Aug 2015
Edited: James Tursa on 3 Aug 2015
Do you inadvertantly have a variable called "input" in your workspace?

4 Comments

yes so you can input the number you want to go to
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.
woops read that wrong sorry, and no
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.

This question is closed.

Tags

Asked:

on 3 Aug 2015

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!