Generate Contour Given X, Y and Z vectors

前端 未结 2 1743
轻奢々
轻奢々 2020-12-20 05:40

Given 3 vector-pair, X, Y and Z, how to generate the contour? I understand that we need to make use of the contour plot. But the thing

相关标签:
2条回答
  • 2020-12-20 06:23

    Yes. Use the Tricontour tool. It is found on the file exchange (on Matlab Central.) This does the contouring as you desire directly, without forcing you to use meshgrid and griddata.

    0 讨论(0)
  • 2020-12-20 06:27

    MATLAB addresses this need of yours fairly succinctly.

    What you need to do is use meshgrid to two-dimensionalize your X and Y vectors. Here is a simple example to demonstrate how to generate a contour plot of z = sin (x^2 + x*y^2):

    x = -10:0.1:10;
    y = -10:0.1:10;
    [x,y] = meshgrid(x,y);
    z = sin(x.^2+x.*y.^2);
    contour(x,y,z)
    

    Note the use of the .^ and .* notations, which forces MATLAB to conduct an element-by-element evaluation of the z matrix, making it 2D in the process.

    0 讨论(0)
提交回复
热议问题