How to get an expression from a textbox in GUI?

조회 수: 1 (최근 30일)
Péter Hauschild
Péter Hauschild 2021년 4월 24일
편집: Shadaab Siddiqie 2021년 4월 27일
Hi!
I'm working on a program in GUI which purpose is to solve non-linear equations. My idea is a simple interface with 4 buttons, axes and a text field where the user can write mathematical expressions (like @(x) 4-4*x^2-exp(x) ), hit a button with a predefined solver, and the program solves the eqation. (A have the functions for the solver already and it works) I know I should use the get() function to get the expression from the text field, but it cannot run, because there is an error somewhere. I tried to change the fromat of expression with str2sym() function but it didn't work. My idea is the following for the push button:
syms x
f=str2sym(get(handles.edit1,'string'))
myfunction(f)
Thank you for your answers!

답변 (1개)

Shadaab Siddiqie
Shadaab Siddiqie 2021년 4월 27일
편집: Shadaab Siddiqie 2021년 4월 27일
From my understanding you want to get a equation from the textbox of the GUI. You can use inline like so:
equ=get(handles.edit1,'Sring');
f=inline(equ,'x') % this makes function f with independent variable x, f(x)
In case there are multiple variables please refer inline.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by