Only one function doesn't work only after the app designer program is compiled

조회 수: 5 (최근 30일)
When I try to run directly on app designer, it works completely fine but when I compile it as a standalone app, it just gets stuck on one function. The sturtup function still works fine but when it comes to the this function it just freezes.
First I thought that it might be "first time running an exe file issue" and it needs some time. So, I left it for hours and still nothing happened. Then to be sure that this function is the problem I gave it some values instead of using the function and again it worked fine fine!!
The function is just a 4input-3output function with a for loop and 3 integral at the end. and It's called by pressing a Button.
methods (Access = private)
%--------------------------------------------------------------------------------------------------------
function [Bx,By,Bz] = Magnetic_field_solenoid_spherical1(~,r0,theta0,phi0,I)
mu0=4*pi;
B=5;
n=50;
dBxt=0;
dByt=0;
dBzt=0;
syms phi z0
%%%some maths...
z01=linspace(-B,B,n);
for z02= z01
R_distance2=R_distance1(phi,z02);
Cross_result2=Cross_result1(phi,z02);
dbx=mu0.*I.*Cross_result2(1,1)/(4.*pi.*R_distance2.^3);
dby=mu0.*I.*Cross_result2(1,2)/(4.*pi.*R_distance2.^3);
dbz=mu0.*I.*Cross_result2(1,3)/(4.*pi.*R_distance2.^3);
dBxt=dBxt+dbx;
dByt=dByt+dby;
dBzt=dBzt+dbz;
end
if dBxt~=0 && isnan(dBxt)==0
Bxt=matlabFunction(dBxt);
Bx = integral(Bxt,0,2*pi);
else
Bx=0;
end
if dByt~=0 && isnan(dByt)==0
Byt=matlabFunction(dByt);
By = integral(Byt,0,2*pi);
else
By=0;
end
if dBzt~=0 && isnan(dBzt)==0
Bzt=matlabFunction(dBzt);
Bz =integral(Bzt,0,2*pi);
else
Bz=0;
end
end
%--------------------------------------------------------------------------------------------------------
function [Bx,By,Bz] = Magnetic_field_solenoid_cartesian1(app,x,y,z,I)
phi = atan2(y,x);
theta= atan2(sqrt(x.^2 + y.^2),z);
r = sqrt(x.^2 + y.^2 + z.^2);
[Bx,By,Bz] = Magnetic_field_solenoid_spherical1(app,r,theta,phi,I);
end
end
Only the second function (Magnetic_field_solenoid_cartesian1) is used directly.
[Bx,By,Bz] = Magnetic_field_solenoid_cartesian1(app,x,y,z,I);

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 31일
MATLAB Compiler cannot compile anything in the symbolic toolbox.
The form of your equation is fixed for any particular n value, and you have hardcoded n. Therefore you can go into another session and generate the entire equation in symbolic form, and use matlabFunction with the 'vars' option to force a particular order of variables and force particular variables to be bundled into one parameter. Use the 'file' option to have the code be written to a .m file. Now go back to the original code and alter it to put the inputs into the proper order and call the already-generated m file. As the generated file will be completely numeric, the result will not need the symbolic toolbox.

추가 답변 (1개)

Steven Lord
Steven Lord 2020년 1월 31일
syms phi z0
This requires Symbolic Math Toolbox which is an ineligible product for MATLAB Compiler.
Depending on what "some maths" is, you may be able to perform the symbolic calculations in MATLAB and generate a matlabFunction that you then include in your application for use when your application is compiled. The isdeployed function may be of use to you in this case.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by