The error is occurring when the user enters a choice that is non-numeric and the conversion from str2num is empty (i.e. []) which is NOT a logical scalar value operand to the (missing?) or () operator. (In the Command Window type str2num('hello') and observe the result.)
To get around this, you could convert the string to a number and check that it is not empty and equal to one, OR compare the string
choiceStr = input('enter something:','s');
choiceNum = str2num(choiceStr);
if (~isempty(choiceNum) && choiceNum==1) || lower(choiceStr) == 'load the data'
disp('loading the data');
end
Even the above is not quite correct. When comparing strings it is preferable to use the strcmp or strcmpi functions. Since you are not interested case (because of the lower) then just use strcmpi
choiceStr = input('enter something:','s');
choiceNum = str2num(choiceStr);
if (~isempty(choiceNum) && choiceNum==1) || strcmpi(choiceStr,'load the data')==1
disp('loading the data');
end
Try the above and see what happens!
Best Answer