Populating 2D meshgrid of a function of four variables

조회 수: 1 (최근 30일)
Valeri Aronov
Valeri Aronov 2021년 8월 15일
댓글: Valeri Aronov 2021년 8월 16일
I have a function:
function [y, Grad, Hess] = Target(x)
...
end;
where x's size is 4 (a vector of 4 variables).
How to plot a contour of Target() using a meshgrid of two variables? Something like this code:
xC1 = linspace(0.1, 1.9);
yR1 = linspace(0.1, 1.9);
[XC1, YR1] = meshgrid(xC1, yR1);
% this is wrong: [Z, ~, ~] = Target([XC1, 1, YR1, 1]); how to do it right?
contour(XC1, YR1, Z)

채택된 답변

Matt J
Matt J 2021년 8월 15일
편집: Matt J 2021년 8월 15일
As long as you don't care about efficiency,
fun=@(x,y) Target([x,1,y,1]);
Z=arrayfun(fun, XC1,YR1);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by