2017-03-09 67 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{:};