用作元胞数组的 Octave 输入参数

Octave input arguments to function as cell array

我想将参数作为元胞数组输入八度函数:

function x = myfunc(a_string, an_int)
  printf("a string: %s\n", a_string);
  printf("an int: %d\n", an_int);
end

myfunc("a", 1);
b = {"a", 1};
myfunc(b); % should do the same thing as myfunc("a", 1)

有什么方法可以轻松做到这一点?

您需要使用 {:} 索引将元胞数组的内容扩展为函数的多个输入。 {:} 索引创建一个逗号分隔的列表,其行为与多个输入一样。

myfunc(b{:})