I'm trying to write some code that asks a user for two numbers and checks that the second is not less than the first.
If the user enters anything other than a number they should be prompted to try again.
I'm having trouble distinguishing between char and double and I now have an error that I am not sure what it means.
Here is my code:
A = ''; %char
while isempty(str2num(A)) A= input('Please enter a number: ','s');endA = str2num(A); %double
B = ''; %charwhile true while isempty(str2num(B)) %char B= input('Please enter a number: ','s'); %char end while ~isempty(str2num(B)) %char B = str2num(B); %double if B < A %double B= input('B less than A, try again: ','s'); %char else B = num2str(B); %char break end B = num2str(B); %char break end end B = str2num(B); %double%need A and B to be doubles for plotting......
Here is the error:
EDU>> Untitled2Please enter a number: 3Please enter a number: 6Operation terminated by user during int2str (after line 32)In num2str (line 68) s = int2str(x); % Enhance the performance
In Untitled2 (line 19) B = num2str(B); %char
Any help would be much appreciated as Matlab has been outwitting me for the last eleven hours.
Cheers
Steve
Best Answer