Populating 2D meshgrid of a function of four variables

1 visualización (últimos 30 días)
Valeri Aronov
Valeri Aronov el 15 de Ag. de 2021
Comentada: Valeri Aronov el 16 de Ag. de 2021
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)

Respuesta aceptada

Matt J
Matt J el 15 de Ag. de 2021
Editada: Matt J el 15 de Ag. de 2021
As long as you don't care about efficiency,
fun=@(x,y) Target([x,1,y,1]);
Z=arrayfun(fun, XC1,YR1);

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by