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

1 vue (au cours des 30 derniers jours)
Peter weber
Peter weber le 1 Sep 2015
Modifié(e) : Peter weber le 2 Sep 2015
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');

Réponse acceptée

Walter Roberson
Walter Roberson le 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 commentaires
Walter Roberson
Walter Roberson le 2 Sep 2015
Remove the last 'end' from textresult_CreateFcn
Peter weber
Peter weber le 2 Sep 2015
Modifié(e) : Peter weber le 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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by