0

Say I want to assign values to dimension variables x and y in single input prompt that goes like,

'Enter x and y'

We do it this way in C

scanf(%f,%f,&x,&y)

1 Answer 1

2

You can have input return a string and then parse that string with sscanf two yield a two-element array which we can then assign to x and y.

str = input('Please enter two numbers: ', 's');
nums = sscanf(str, '%f,%f');
x = nums(1);
y = nums(2);

Alternately, you could just prompt the user to enter the data in a specific format which will automatically create a cell array

nums = input('Enter two numbers in the form {num1, num2}');
[x, y] = nums{:};
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.