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

1 回表示 (過去 30 日間)
Peter weber
Peter weber 2015 年 9 月 1 日
編集済み: Peter weber 2015 年 9 月 2 日
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 件のコメント
Walter Roberson
Walter Roberson 2015 年 9 月 2 日
Remove the last 'end' from textresult_CreateFcn
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 Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by