多输入matlab

时间:2013-08-24 05:38:33

标签: matlab

您能否告诉我如何在matlab中从用户那里获得多个输入?我想过直接获得一个数组,但这似乎不可能。我尝试了以下

     velocity = input('Enter the velocities you want the aircraft to have at every node with space in between(m/s)','s');

以后使用分隔符来读取空格之间的数字。但即便如此,我也不确定如何使用内置功能。<​​/ p>

     [u,remain] = strtok(velocity);

如果无法直接获取多个输入,我如何将上述内容放入循环中,以便我可以读取所有数字?如果qustion非常简陋,我很抱歉,你的帮助将会受到高度赞赏。

2 个答案:

答案 0 :(得分: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'

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

答案 1 :(得分:1)

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

result = input('prompt');

Matlab将提示您输入“提示”,您可以输入例如[1 2 3]。结果将是带有前一个数字的向量。