Does my code have an error?
2 views (last 30 days)
Show older comments
Erwin Avendaño
on 6 Nov 2017
Commented: Walter Roberson
on 6 Nov 2017
Matlab works fine but when I do an executable file this button does not work in my program is the only one that does not work is the one with the longest code I can not understand because it is the only button that does not work when I convert it to executable file. I repeat in matlab if the code of this button works and it does not mark error but when I use this button in the ejectable it does not work
function pushbutton3_Callback(~, ~, handles)
syms x %variable simbolica x
f=get(handles.edit8,'string');
xl=str2double(get(handles.edit3,'string'));
xu=str2double(get(handles.edit5,'string'));
tol=str2double(get(handles.edit4,'string'));
E=100;
xa=100;
i=0;
while(tol<E)
xr=(xl+xu)/2;
fxl=subs(f,x,xl);
fxr=subs(f,x,xr);
m=fxl*fxr;
if(m)<0
xu=xr;
else
xl=xr;
end
E=abs(xr-xa);
xa=xr;
i=i+1;
end
xr;
vpa(E,5)
set(handles.edit6,'string',xr);
set(handles.edit9,'string',E);
% --- Executes on button press in pushbutton4.
0 Comments
Accepted Answer
Walter Roberson
on 6 Nov 2017
Edited: Walter Roberson
on 6 Nov 2017
It is never possible to compile anything from the Symbolic Toolbox into an executable.
It is also not possible to use eval() or evalc() or inline(). str2func() can only be used at compile to for constant expressions, which then compiled into fixed functions.
It is not possible in a compiled executable to dynamically create a symbolic function or an anonymous function based upon user input.
The only work-around for this is for you to create your own expression string parser that analyzes the user input in terms of functionality you have already compiled in, starting with numeric values and doing operations on them according to what your program understands of the string. See https://www.mathworks.com/matlabcentral/fileexchange/24026-growing-a-compiler?focused=6785573&tab=example
3 Comments
Walter Roberson
on 6 Nov 2017
This is not something that should be done as a compiled executable. It is not reasonable for you to be expected to do this in a compiled executable unless your class has studied parsing and compiler techniques.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!