matlab - 多输入Matlab

标签 matlab

您能告诉我如何在 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/

相关文章:

matlab - 为什么 var() 不将整数输入转换为 double 而不是抛出错误消息?

matlab - 当 printf 位于从 s-function 调用的单独的 c 文件中时,如何使它工作?

MATLAB - xy曲线下的条纹区域(弯矩分布)

matlab - 在 MATLAB 中,每次值从 1 变为 0 时如何查找向量中的索引?

algorithm - 需要帮助理解这个 MATLAB 函数实现

c++ - MATLAB "fminunc"的良好 C++ 替代品?

Matlab 编译器运行时库

algorithm - 将 block 对角矩阵乘以向量的有效方法

matlab - OpenCV-如何使用C++计算黎曼距离?

MATLAB:图像角坐标和引用元胞数组