0

I cant find how to write the code so my Matlab script re-ask the question since the user input was in wrong format.

My code is very simple and it all works but it just skips if the user gives wrong format for a second time. Is it possible in Matlab script to have the question repeated since a if fails and the input does not pass what is asked for?

  A1 = input('State the vector: ');
    if length(A1) < 3 || length(A1) > 3
    disp('The input needs 3 values.')
    A1 = input('State the vector again please: ');
  end

How do i make it ask the question untill it passes the length of index 3?

1
  • Douh!! Haha! Thanks Isaac!! Saved me some hours :D Commented Nov 13, 2012 at 20:04

1 Answer 1

2

Try this:

A1 = input('State the vector: ');
while(1)
    if length(A1) ~= 3
        disp('The input needs 3 values.');
        A1 = input('State the vector again please: ');
    else
        break;
    end
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.