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

2 views (last 30 days)
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');

Accepted Answer

Walter Roberson
Walter Roberson on 2 Sep 2015
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 Comments
Walter Roberson
Walter Roberson on 2 Sep 2015
Remove the last 'end' from textresult_CreateFcn
Peter weber
Peter weber on 2 Sep 2015
Edited: Peter weber on 2 Sep 2015
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

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!