How to create multiple matlabFunctions from an array containing symbolic expressions?

1 回表示 (過去 30 日間)
snhah
snhah 2020 年 2 月 24 日
回答済み: Sahithi Metpalli 2020 年 3 月 2 日
I have an array containing a number of symbolic expressions, for example:
syms x y z
expressions = [x, y, z, x^2, y^2, z^2, x*y, x*z, y*z];
How can I create a matlabFunction for each expression without manually defining each one?
Is it possible to create an array of matlabFunctions?
Thanks
  2 件のコメント
darova
darova 2020 年 2 月 24 日
  • How can I create a matlabFunction for each expression without manually defining each one?
What about matlabFunction?
snhah
snhah 2020 年 2 月 24 日
編集済み: snhah 2020 年 2 月 24 日
@darova I mean, say for example, in a for loop...

サインインしてコメントする。

回答 (1 件)

Sahithi Metpalli
Sahithi Metpalli 2020 年 3 月 2 日
According to my understanding you can use a cell array of function handles for the symbolic expressions using the inbuilt function matlabFunction as shown below.
syms x y z
expressions = [x, y, z, x^2, y^2, z^2, x*y, x*z, y*z];
for i=1:length(expressions)
FunctionHandle{i} = matlabFunction(expressions(i));
end

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by