MATLAB: Not effective validation algorithm for input format

checkisnumericMATLABnumericstring

Hello everyone, I am asking as input, coordinates of quadrilateral vertices and I am adding an extra layer for format checking. Simply speaking inputs must be numerical.
vx=zeros(1,4);
vy=zeros(1,4);
vertices=['A'; 'B'; 'C'; 'D'];
fprintf('\nPlease enter the coordinates of vertices:\n');
for cnt=1:4
fprintf('\n For vertix <strong> %s </strong>', vertices(cnt));
fprintf(' :\n');
vx(cnt) = input(' Χ=');
vxtest=isnumeric(vx(cnt));
while vxtest==0
fprintf('ERROR: Non numerical character, try again.\n');
vx(cnt) = input(' Χ=');
vxtest=isnumeric(vx(cnt));
end
vy(cnt) = input(' Y=');
vytest=isnumeric(vy(cnt));
while vytest==0
fprintf('ERROR: Non numerical character, try again.\n');
vy(cnt) = input(' Y=');
vytest=isnumeric(vy(cnt));
end
end
vx=vx(1:4);
vy=vy(1:4);
But still it is possible to put a string as an input and continue to the next coordinate. At the end, there is an output area of a quadrilateral with vertices out of string coordinates.
Thanks in advance!

Best Answer

Try this
vx=zeros(1,4);
vy=zeros(1,4);
vertices=['A'; 'B'; 'C'; 'D'];
fprintf('\nPlease enter the coordinates of vertices:\n');
for cnt=1:4
fprintf('\n For vertix <strong> %s </strong>', vertices(cnt));
fprintf(' :\n');
temp = input(' Χ=');
vxtest=isnumeric(temp);
vx(cnt) = temp;
while vxtest==0
fprintf('ERROR: Non numerical character, try again.\n');
temp = input(' Χ=');
vxtest=isnumeric(temp);
vx(cnt) = temp;
end
temp = input(' Y=');
vytest=isnumeric(temp);
vy(cnt) = temp;
while vytest==0
fprintf('ERROR: Non numerical character, try again.\n');
temp = input(' Y=');
vytest=isnumeric(temp);
vy(cnt) = temp;
end
end
vx=vx(1:4);
vy=vy(1:4);