Index exceeds matrix dimensions. Please help.
Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Ältere Kommentare anzeigen
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.
Antworten (1)
James Tursa
am 3 Aug. 2015
Bearbeitet: James Tursa
am 3 Aug. 2015
0 Stimmen
Do you inadvertantly have a variable called "input" in your workspace?
4 Kommentare
Derrick Edmiston
am 3 Aug. 2015
James Tursa
am 3 Aug. 2015
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
am 3 Aug. 2015
James Tursa
am 3 Aug. 2015
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.
Diese Frage ist geschlossen.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!