필터 지우기
필터 지우기

Does my code have an error?

조회 수: 2 (최근 30일)
Erwin Avendaño
Erwin Avendaño 2017년 11월 6일
댓글: Walter Roberson 2017년 11월 6일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 6일
편집: Walter Roberson 2017년 11월 6일
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
Erwin Avendaño
Erwin Avendaño 2017년 11월 6일
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 2017년 11월 6일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by