필터 지우기
필터 지우기

integration of equation using gui

조회 수: 2 (최근 30일)
Alicja
Alicja 2023년 1월 17일
댓글: John D'Errico 2023년 1월 17일
Hello, I want to find integration of equation using gui. That's my code, why it doesn't work? Please help me and explain in very simple words, I'm at the very beginning of learning matlab.
function calculator
% tworzenie okna GUI
f = figure('Visible','off',...
'Position',[480,500,500,480]);
integration = uicontrol('Style','pushbutton',...
'String','integration',...
'Position',[315,170,70,25],...
'Callback',@integration);
hinput_g = uicontrol('Style','edit',...
'Position',[120, 200,240,40],...
'String','function');
set(f,'Name','Moja aplikacja GUI');
set(f,'Visible','on');
function integration(~,~)
x = get(hinput_g,'String');
x=str2func(x);
syms c
c= int(x)
msgbox(sprintf(c));
end
end
  댓글 수: 3
Alicja
Alicja 2023년 1월 17일
yes, autocorrect, thanks
John D'Errico
John D'Errico 2023년 1월 17일
Blasted spell checkers. I'll never forgive the old IBM utility, which many years ago, could find only one replacement for what it thought was my mis-spelled name of D'Errico in a document. It wanted to substitute "derelict" for my name.

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

채택된 답변

John D'Errico
John D'Errico 2023년 1월 17일
편집: John D'Errico 2023년 1월 17일
I can't execute this code in online MATLAB. So we can just look at what happens inside the function caled integration.
First, it extracts a variable named x, as a string from the gui field. Perhaps it was this:
x = 'y^2 + 2';
Next, you use str2func. That is incorrect. You don't want to make it a function handle like this:
x=str2func(x)
That is because int does not use function handles. Instead, what you wanted to do was to use str2sym.
x = str2sym(x)
x = 
This is something that int can now use. As you can see, MATLAB now thinks x is a symbolic expression.
Next, you create a symbolic variable named c. There is no need to do so, since immediately afterwards, you assign the result of int to c. That overwrites anything you did before. So the "syms c" command is wasted. Not important though, except for the CPU cycles thrown in the bit bucket. One day you will care about wasted CPU cycles.
Finally, you use int. That will work now.
c= int(x)
c = 
However, can you use sprintf directly on c? No. However, you can convert c into a character form.
char(c)
ans = '(y*(y^2 + 6))/3'
And you can put that into a string field in a messagebox.
  댓글 수: 1
Alicja
Alicja 2023년 1월 17일
It works! Thank you so much, I get it now!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by