Plotting a contour of a function with one input variable
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
My function essentially has 2 inputs , x and y, but they're in the form theta = (x;y). So the first line of my code is x = theta(1,1), y = theta(2,1), and my function takes one input theta which should be a 2x1 matrix.
I need to plot a contour of the function with x and y taking certain values. But when I use "fcontour" I get 'not enough input arguments'. I'm not able to change the number of inputs for my function, it has to take a single input theta.
Any help would be appreciated for the contour plot! Thank you
댓글 수: 0
답변 (1개)
Chris
2021년 11월 2일
편집: Chris
2021년 11월 2일
exes = linspace(-2*pi,2*pi);
whys = exes;
theta = [exes',whys'];
takeOneInput(theta)
You can pack as much as you want into an input, depending on the data type. This one uses fcontour.
theta2.fun = @(x,y) sin(x) + cos(y);
theta2.xyinterval = [-2*pi,2*pi, -2*pi, 2*pi]
takeAnotherInput(theta2)
function takeOneInput(theta)
[x,y] = meshgrid(theta(:,1),theta(:,2));
f = sin(x) + cos(y);
contour(theta(:,1),theta(:,2),f);
end
function takeAnotherInput(theta)
fcontour(theta.fun,theta.xyinterval);
end
But if you are designing the function, why is it only permitted to take one input?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!