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

前端 未结 7 690
猫巷女王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 05:16

    Just make the function take a single argument.

    function result = func(a)
        if ~isvector(a)
            error('Input must be a vector')
        end
    end
    
    0 讨论(0)
提交回复
热议问题