您能告诉我如何在 matlab 中获取用户的多个输入吗?我想过直接获取数组,但这似乎不可能。我尝试了以下方法
velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');
之后使用分隔符来读取空格之间的数字。但即便如此,我也不知道如何使用内置函数。
[u,remain] = strtok(velocity);
如果没有办法直接获取多个输入,我怎样才能将上面的内容放入循环中,以便我可以读取所有数字?如果问题非常简单,我很抱歉,我们将非常感谢您的帮助。
最佳答案
将数组作为输入
>> velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');
Enter the velocities you want the aircraft to have at every node with space in between(m/s) [1 2 3]
>> velocity
velocity =
[1 2 3]
然后可以使用velocity(1)、velocity(2)、...
等。
或者如果您打算提供逗号分隔输入,请使用正则表达式
>> velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');
Enter the velocities you want the aircraft to have at every node with space in between(m/s)1,2,3
>> result=regexp(velocity,',','split')
result =
'1' '2' '3'
(同样,您也可以使用空格来分隔输入)
关于matlab - 多输入Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18415318/