MATLAB: Trouble with char and doubles in code

variables

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');
end
A = str2num(A); %double



B = ''; %char
while 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>> Untitled2
Please enter a number: 3
Please enter a number: 6
Operation 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

Thank you for the quick reply and taking time to address my question. I see the problem that I have with the while loop and will have a go at fixing it. The reason that I have gone for coding in this way is to try to avoid the automatic Matlab error that is displayed when anything other than a number is entered into a double:
Error using input
Undefined function or variable 'h'.
Error in Untitled3 (line 1)
A= input('enter a number ');
Earlier today I asked another question to see if there was a way of suppressing this error before being guided along the lines of the code that you have perused. I have written some code that works with the error, but if symbols such as & or £ are entered the program exits:
A= input('enter a number ');
while isempty(A)== 1
A= input('try again ');
end
B= input('enter a number ');
while true
if isempty(B)== 1;
B= input('try again ');
elseif B < A;
fprintf('B must be greater than A %.2f - enter a value ',A);
B= input('');
else
break
end
end
I’ve tried to use the isnan() function but if I don’t really get it:
a = input('enter number: ') %double
b = isnan(a)
enter number: 2
a =
2
b =
*0*
enter number: f
Error using input
Undefined function or variable 'f'.
Error in Untitled2 (line 30)
a = input('enter number: ')
a = input('enter number: ','s') %string
b = isnan(a)
enter number: 4
a =
4
b =
*0*
enter number: d
a =
d
b =
*0*
??????