2

你能告诉我如何在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);

如果没有办法直接获取多个输入,我怎样才能将上面的内容放在一个循环中,以便我可以读取所有数字?如果问题非常基本,我很抱歉,您的帮助将不胜感激。

4

2 回答 2

3

将数组作为输入

>> 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'

(类似地,您也可以使用空间来分隔输入)

于 2013-08-24T05:52:19.793 回答
1

这可以通过以下方式完成:

result = input('prompt');

Matlab 将提示您输入“提示”,您可以输入例如 [1 2 3]。结果将是向量,其中包含先前的数字。

于 2013-08-24T06:02:52.037 回答