Azzera filtri
Azzera filtri

Does my code have an error?

2 visualizzazioni (ultimi 30 giorni)
Erwin Avendaño
Erwin Avendaño il 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.

Risposta accettata

Walter Roberson
Walter Roberson il 6 Nov 2017
Modificato: Walter Roberson il 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 Commenti
Erwin Avendaño
Erwin Avendaño il 6 Nov 2017
Could you show me an example for this code? the truth if I am lost in this subject, my teacher did not teach us anything of this and I have to program a guide that has 9 methods and I only need this PLEASE
Walter Roberson
Walter Roberson il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by