Matlab:如何在 matlabFunction 中指定输入? [英] Matlab: How to specify input in matlabFunction?

查看:62
本文介绍了Matlab:如何在 matlabFunction 中指定输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

matlabFunction() 是一个可以将符号转换为匿名函数的函数.但是如何指定在匿名函数上出现哪些输入参数?

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?

例如

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

它返回一个句柄:

func =

  function_handle with value:

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

但是如何让它返回:?

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

整个 x 是输入参数,而不是它的每个元素.当 x 有很长的列时,这可能非常有用.

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

推荐答案

你可以输入 x 的元素作为 逗号分隔列表func 首先x 转换为元胞数组.

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{:})

这篇关于Matlab:如何在 matlabFunction 中指定输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆