2017-03-09 68 views

回答

2

你可以有input返回一个字符串,然后解析与sscanf两块串产生两个元素的数组,然后我们可以分配给xy

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

或者,你可能只是提示用户输入特定格式的数据将自动创建一个单元阵列

nums = input('Enter two numbers in the form {num1, num2}'); 
[x, y] = nums{:};