While Loop Errors with Opperators
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Can someone please tell me why I keep getting the error "Undefined operator '<' for input arguments of type 'cell' as well as if it works, it goes on an infinite loop and has to be stopped instead of inputting again?
Boat = menu('Would you like a recommended setup?','Yes','No');
if Boat == 2
Setup = msgbox('Okay, have a good day! Remember to visit myfwc.com for license and species regulations and check your local fishing and weather reports!')
elseif Boat == 1
BoatStyle = menu('Please select the style the most describes your boat:','Center Console','Viking','Flat Bottom','Yacht','Pontoon');
if BoatStyle == 1
BoatStyle = inputdlg('Please enter the length of your boat')
while isempty(BoatStyle) || BoatStyle < 9 || BoatStyle > 61
msgbox('Error. Please input realistic boat dimentions between 10ft - 60ft.')
if BoatStyle >= 10 && BoatStyle <= 60
msgbox('This is a good size boat.')
end
end
end
end
0 commentaires
Réponses (2)
Walter Roberson
le 27 Avr 2020
inputdlg does not return numeric values: it returns a cell array of character vectors. You need to use str2double to get the numeric equivalent.
2 commentaires
Walter Roberson
le 27 Avr 2020
BoatStyle = str2double(inputdlg('Please enter the length of your boat'));
while isnan(BoatStyle) || BoatStyle < 9 || BoatStyle > 61
Deepak Gupta
le 27 Avr 2020
Hi Paul,
As Walter has mentioned in his answer, inputdig returns data in cells and not numeric values. And therefor cell values can't be directly used with logical operator. You need to convert this cell value to a numerical before applying logical operator.
Apart from that, you are using a while loop to check conditions and if condition true, loop will run. But there is no condition to stop this loop so it will run continuosly. I think in this case, an if loop is sufficient.
BoatStyle = menu('Please select the style the most describes your boat:','Center Console','Viking','Flat Bottom','Yacht','Pontoon');
if BoatStyle == 1
BoatStyle = str2num(cell2mat(inputdlg('Please enter the length of your boat')))
if isempty(BoatStyle) || BoatStyle < 9 || BoatStyle > 61
msgbox('Error. Please input realistic boat dimentions between 10ft - 60ft.')
if BoatStyle >= 10 && BoatStyle <= 60
msgbox('This is a good size boat.')
end
end
end
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!