while loops. Why is it not stopping
Ältere Kommentare anzeigen
hi all i am doing a while loops, and i want it to stop when i entered the number 1 or the word load the data, but it doesn't want to stop when i enter the number 1 but it works fine when i enter the word 'load the data'. Plz check it out for me.
questionLine{1} = 'Access the feature by entering the number or the word?'
questionLine{2} = '1. Load the data';
questionLine{3} = '2. Load new data';
questionLine{4} = '3. Data fitting';
questionLine{5} = '4. Filter data';
questionLine{6} = '5. quit';
while (~isempty( choicenum) && choicenum~=1) strcmpi(choiceStr,'load the data')~=1 % when choicenum is not 1 or choicestr is not load the data. run the while loops.
question = [1:2,6]; % displaying the options.
for i = question
disp(questionLine{i})
end % just printing the questionLines.
choiceStr=input('Enter the word or the number:','s');
choicenum=str2num(choiceord);
disp('Enter a valid number or word')
end
Akzeptierte Antwort
Weitere Antworten (1)
Image Analyst
am 21 Jun. 2014
How about
button = 1
while button == 1
button = menu('What do you want to do?', 'Load the data', 'Quit');
% Code to load the data, etc.
end
2 Kommentare
Jian Gui
am 21 Jun. 2014
Image Analyst
am 21 Jun. 2014
But you're allowed to use input(), str2num(), disp(), etc. in your homework solution? Why? What's so bad about menu() and not the others????
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!