Compiled exe app doesn't work on a function used within another function

1 次查看(过去 30 天)
So I have an app developed by MATLAB app designer. I have put my main backend code in a function and call that function on button press.
Here is my problem: While running in app designer everything is fine, but when I compile it as a stand-alone exe file and install it, the code doesn't work properly. So I used messages in different parts of code to debug it and I find out that it stops as soon as it reaches first function used in the main function. Here is a demonstration of my main code, note that this is the main function called by app designer:
function maincode
x = 1;
y = 2;
z = secondfunction(x,y);
end
and my secondfunction is saved in another .m file (which I include in additional files before packaging)
function [sum] = secondfunction(inputArg1,inputArg2)
syms x
eqn = inputArg1*x + inputArg2 == 0;
sum = solve(eqn,x);
end
UPDATE: I debuged it further and now I am 100% sure that it has to do something with "syms" and "solve".
  2 个评论
Walter Roberson
Walter Roberson 2024-8-18
and my secondfunction is saved in another .m file
You appear to have accidentally named your second function maincode .
In theory, functions are to be invoked according to the file name, not according to the function line name, so in theory as long as your second function file name was secondfunction.m the code should have worked. But it would not entirely surprise me if MATLAB gets confused by this situation.
Amirreza Farzaneh
Amirreza Farzaneh 2024-8-18
I am sorry for my mistake Walter. I updated my question, see if you got anything? thank you.

请先登录,再进行评论。

回答(1 个)

halleyhit
halleyhit 2024-8-19
编辑:halleyhit 2024-8-19
In your second function, you are using syms, which is from Symbolic Math Toolbox. As shown in doc:
It is not supported in Compiler workflow.
  4 个评论
Amirreza Farzaneh
Amirreza Farzaneh 2024-8-19
Yes I know that, but it was a placeholder. My actual equations are ode and pde. Any way to compile them using syms? Or alternatives?
Steven Lord
Steven Lord 2024-8-19
Either solve them symbolically then generate a MATLAB function to evaluate that solution without using Symbolic Math Toolbox and use the generated function in your application (as shown on this documentation page) or switch to solving them numerically using the functions included in this documentation category.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Code Generation 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by