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 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