How do I convert a string input to an executable equation?
39 次查看(过去 30 天)
显示 更早的评论
I am developing a nice GUI for my company (those who don't want to code). It will give them areas to add their equations and define their constants, blah blah blah. The challenge I'm running into is grabbing the input string from the user and converting that to an executable equation or expression. Any thoughts?
采纳的回答
Salaheddin Hosseinzadeh
2014-3-13
you can simply use 'inline'
I've precviously written and equation solver, and it works like a charm, it also has a GUI and it solves any sort of euquation , if you enter them correctly, also assuming that the independet variable is always x
equ=get(handles.edit1,'Sring');
f=inline(equ,'x') % this makes function f with independent variable x, f(x)
Good Luck!
2 个评论
Salaheddin Hosseinzadeh
2014-3-13
You can define functions with more than one or two independet variables using inline.
Now that you got how to do it just take a look at MATLAB doc help to get master.
Glad that it helped ;)
更多回答(2 个)
Joseph Cheng
2014-3-13
编辑:Joseph Cheng
2014-3-13
Depending on what their equation uses eval (see http://www.mathworks.com/help/matlab/ref/eval.html) might work. if i remember correctly some toolboxes and functions are not supported if your GUI is compiled into a standalone. So put the edit box string into the eval
eval(get(handles.editbox1,'String'));
2 个评论
Karan Gill
2017-9-29
编辑:Karan Gill
2017-10-17
>> syms f(x)
>> function1 = input('Please enter the function: ', 's');
Please enter the function: sin(x)
>> f(x) = str2sym(function1)
f(x) =
sin(x)
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!