Matlab: How to specify input in matlabFunction?

泄露秘密 提交于 2019-12-14 02:37:16

问题


matlabFunction() is a function that can convert symbolic to anonymous function. But how to specify what input arguments to be appeared on the anonymous function?

For example,

x = sym('x', [3, 1])
func = matlabFunction(x)

It returns a handle with:

func =

  function_handle with value:

    @(x1,x2,x3)[x1;x2;x3]

But how to make this to be returned:?

@(x) [x(1); x(2); x(3)]

that the whole x is the input arguments, not every element of it. This could be extremely useful when x has very long colums.


回答1:


Instead of making that anonymous function, you can input the elements of x as a comma separated list to func by first converting x to a cell array.

xcell = num2cell(x);
func(xcell{:})


来源:https://stackoverflow.com/questions/54709163/matlab-how-to-specify-input-in-matlabfunction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!