Using matlabFunction to run solve() in a deployed app

18 次查看(过去 30 天)
Hi. I'm trying to use matlabFunction to run solve() statements, so the app will be deployed fine. I have this example code:
if ~isdeployed()
syms x
eq = solve(x + 5 == 8, x);
fun = matlabFunction(eq, 'File', 'SolveTest.m');
clear x eq fun
else
fun = @SolveTest;
end
app.EditField.Value = SolveTest;
it works fine inside appdesigner, but when I try to deploy it by 'deploytool', I get this error:
Warning: In "test.mlapp", "syms" are excluded from packaging for the MATLAB Runtime environment according to the MATLAB Compiler license. Either remove the file or function from your code, or use the MATLAB function "isdeployed" to ensure the function is not invoked in the deployed component.
how can it be fixed?
I'm using R2022b.

回答(1 个)

Ayush Singh
Ayush Singh 2024-7-10,7:13
Hey Mahdi!
The approach you are taking is correct in using `isdeployed` to differentiate between development and deployment environments. However, you need to ensure that the symbolic operations and the creation of the function file happen only in the development environment.
You can try the modified version of your code, ensuring that symbolic operations and function file generation are only executed in the development environment:
if ~isdeployed()
% Symbolic operations and function file generation
syms x
eq = solve(x + 5 == 8, x);
matlabFunction(eq, 'File', 'SolveTest.m'); % Create the function file
clear x eq
end
% Load the generated function
fun = @SolveTest;
app.EditField.Value = fun();
Ensure that the Generated Function File is Included in the Deployment:
- Make sure that the generated function file 'SolveTest.m' is included in the files to be deployed. You can do this in the deploytool by manually adding 'SolveTest.m' to the list of files to be packaged.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by