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*
??????