How to get 2-variable function from a GUI textbox?

1 次查看(过去 30 天)
Hey
I need to input a 2 variable function like f(x,y) and give x and y lower and upper limit and use numerical methods on it. I did it for 1 variable function(find a GUI) but now there are problems with f(x) turnning into f(x,y) and fevel(fx,x) that cannot be (fx,x,y).
here is .m file and the problem area:
x1 = str2double(get(handles.editx1,'String'));
x2 = str2double(get(handles.editx2,'String'));
fx = vectorize(inline(get(handles.editfunc,'String')));
x = [x1:0.001:x2];
values = feval(fx,x);
maxi=max(values);
mini=(min(values));
if mini > 0
mini = 0;
end;
method = get(handles.pop_int,'Value');

采纳的回答

Walter Roberson
Walter Roberson 2015-9-2
Why not? feval() accepts multiple arguments. And you don't need feval() anyhow for this purpose.
I recommend that you stop using inline() and start using str2func()
fx = str2func(['@(x,y)' vectorize(get(handles.editfunc,'String'))]);
values = fx(x, y);
I suspect you will also be wanting to use ndgrid() to construct the arguments you pass to your function.
  3 个评论
Peter weber
Peter weber 2015-9-2
编辑:Peter weber 2015-9-2
Thanks again but I have another Questions If I may: I want to use I = trapz(y,trapz(x,F,2)) with the above fx=fx(x,y) but it doesn't work... 2. remember that function you mentioned above fx(x,y), how can I change for instance "x" into " a*x+b" or even entirely something else like 5*t-9...greatly thankful in advance

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by