Error when asking if a certain option is valid
Afficher commentaires plus anciens
In my function I have.....(getoption) then in my script I have....(assignment4) heres the other function I have but I'm not having a problem with that yet...(getoption)
So my problem is that when I run my script, I plug in 1 and it keeps on telling me that its invalid which I'm puzzled by. I knows its a simple error to fix but I'm very stuck. Please help
Réponses (1)
Geoff Hayes
le 4 Déc 2015
Garrett - consider using the MATLAB debugger to debug your code. Put a breakpoint at line 6 of the getoption function and run your assignment4 function. Once you have chosen the option (1, 2, or 3) and pressed enter the debugger should pause at
while op <= 3 || op >= 0
where op is the option that you have selected (and so will most likely be an integer). The body of your while loop generates the invalid error message, and this will always occur so long as your conditions are true: op <= 3 or op >= 0. This will always be true if the user enters a 1, 2, or 3! You want something a little different (not quite the negation) but
while op < 0 || op > 3
Try the above and see what happens! You may also want to use ceil to avoid any non-integer inputs
op = ceil(input('Enter matrix option: '));
1 commentaire
Garrett Walton
le 4 Déc 2015
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!