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

1 view (last 30 days)
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 Comments
Walter Roberson
Walter Roberson on 18 Aug 2024
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 on 18 Aug 2024
I am sorry for my mistake Walter. I updated my question, see if you got anything? thank you.

Sign in to comment.

Answers (1)

halleyhit
halleyhit on 19 Aug 2024
Edited: halleyhit on 19 Aug 2024
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 Comments
Amirreza Farzaneh
Amirreza Farzaneh on 19 Aug 2024
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 on 19 Aug 2024
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.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!