【问题标题】:Octave input arguments to function as cell array [duplicate]用作元胞数组的八度输入参数[重复]
【发布时间】:2016-07-16 00:25:47
【问题描述】:

我想将参数作为元胞数组输入到 octave 函数:

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)

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

【问题讨论】:

    标签: matlab function octave cell-array multiple-arguments


    【解决方案1】:

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

    myfunc(b{:})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      相关资源
      最近更新 更多