Want to use a vector as parameter to a function, without having to separate its elements

前端 未结 7 695
猫巷女王i
猫巷女王i 2021-01-03 04:35

If I call a matlab function with: func(1,2,3,4,5) it works perfectly.

But if I do: a=[1,2,3,4,5] %(a[1;2;3;4;5

7条回答
  •  被撕碎了的回忆
    2021-01-03 04:54

    Comma-seperated lists (CSL) can be passed to functions as parameter list,

    so what you need is a CSL as 1,2,3,4,5 constructed from an array.

    It can be generated using cell array like this:

    a=[1,2,3,4,5];
    c = num2cell(a);
    func(c{:});
    

提交回复
热议问题