Works in App designer but not with the standalone program

9 views (last 30 days)
Hi,
I'm trying to create a standalone program for someone without Matlab. The source code is attached here. The program works in App designer but when I created the standalone installation, it doesn't work. It could be due to the .m functions I tried to call which also calls other functions or the symbolic equation I tried to solve. But I don't understand why and how to solve the issue. Could you help please?
Thanks and best regards,
Jianxin Wang
  4 Comments
Mohammad Sami
Mohammad Sami on 27 Jan 2020
You have defined some global variables in your app.
Its better that you don't use global variables. You should add these as properties of your app.
Jianxin Wang
Jianxin Wang on 27 Jan 2020
Edited: Jianxin Wang on 27 Jan 2020
Thankyou, Mohammad. However, the global variables were not the problem as the problem still exits after I deleted them. It turns out that the symbolic definition is not supported in the standalone distribution.
Details here:
Now I need to find a way to work around it.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 27 Jan 2020
MATLAB Compiler and MATLAB Coder cannot be used with Symbolic Toolbox. This is not expected to change any time soon.
  4 Comments
Walter Roberson
Walter Roberson on 29 Jan 2020
There are three important phases in any situation like this:
  1. Set up the equations
  2. Solve the equations as formulas
  3. Substitute numeric values for the variables in the solution formulas in order to get numeric solutions
Setting up the equations is a matter of user interface and file I/O, in order to get down to a particular form of equations with all known parameters substituted. In some cases, the user gets to define the form of the equations dynamically, with the user choosing the number of terms or the user being able to input formulas. In some cases you are able to define the equations in terms of numeric matrices to go into a fixed formula, and in other cases it takes a full dynamic expression. A full dynamic expression can require the Symbolic Toolbox, but sometimes when generating formulas you can get away with character vectors and str2func() . So depending on what expressive power is required, you might be able to get away with just defining numeric arrays for a formula set in advance, or you might be able to get away with constructing a function handle, or you might need the Symbolic Toolbox.
But... MATLAB Compiler and MATLAB Coder cannot handle Symbolic Toolbox (ever), and they also do not support str2func() to generate function handles. Basically, unless you constrain the user to a finite list of pre-defined formulas, You Have A Problem if you are using MATLAB Compiler or MATLAB Coder.
Solving the equations as formulas involves taking in a fully formed set of equations and finding symbolic solutions to them. This involves the Symbolic Toolbox, which is a problem for MATLAB Compiler or MATLAB Coder.
The output of the symbolic solution set is either a symbolic formula or a function handle to (hopefully) pure numeric operations.
Substituting numeric values into the solutions is a matter of using subs() for symbolic formulas, or of generating a function handle using matlabFunction and applying the function handle. If the second phase generated the function handle to operations that can be handled purely numerically, then this third phase might not need the Symbolic Toolbox.
If the user is given enough expressive power in the user interface, then you are stuck not being able to use MATLAB Compiler or MATLAB Coder. Or you could have a server that you send the dynamic formula to and the numeric values, and using a full version of MATLAB, it sends back the results. This option of using a server would need to be carefully considered as it is in danger of violating the MATLAB license agreements. Oddly enough, the less flexibility the user has in setting up the formulas, the less violation of the license agreement there would be.
A typical way of dealing with this issue is to have one user who has access to a full version of MATLAB, and is handed requests with complete information about the form of an equation that needs to be handled. This user takes the full version of MATLAB and does the symbolic setup and symbolic solve() operation, and uses matlabFunction to write the symbolic solution to a .m file. The user with full access to MATLAB could certainly have written a program specifically for this purpose of generating solutions in the form of .m files.
Then the user adds that .m as an additional option to a fixed list of equations in a user interface, with the .m to be invoked if the user choses that equation, and builds the user interface using MATLAB Compiler or MATLAB Coder, and hands out that compiled executable. The compiled executable does not permit the user to dynamically create new expressions, only to select from a menu of expressions, the solution formulas for which have been previously generated.
This arrangement of having one user responsible for doing symbolic work and building a fixed user interface invoking the non-symbolic resulting function, is permitted by the license agreement.
So... if the user needs to be able to do "new" things, then the user needs a full MATLAB, not a compiled executable, but if the user only needs to be able to do one of several pre-determined things, then a compiled executable for that part is fine -- only the user that needs to add more pre-determined choices needs the full MATLAB.
Jianxin Wang
Jianxin Wang on 30 Jan 2020
Thank you, Walter! That is great instruction and I hope Matlab can come up with some examples for this.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!