Plot square surface in Matlab

后端 未结 3 1207
天涯浪人
天涯浪人 2021-01-21 20:56

How to plot a square surface in Matlab?

More exactly I want to plot a square square with value 0.5 surface which is located at X:-1 to X=1 and Y:2.5 to 3.5.

3条回答
  •  长发绾君心
    2021-01-21 21:27

    You need to provide multiple Z-values together with the same X, Y values. A small example:

    >> [X, Y]= meshgrid([1,2,2,3,4], 1:2)
    X =
         1     2     2     3     4
         1     2     2     3     4
    Y =
         1     1     1     1     1
         2     2     2     2     2
    >> Z = [0,0,1,1,0;0,0,1,1,0]
    Z =
         0     0     1     1     0
         0     0     1     1     0
    >> surf(X, Y, Z)
    

    Yields this:

    Step at X=2, slope at X=3..4

    This should be the same in 2D, you just need to wrap you head around which X and Y values to duplicate and adjust the Z-Matrix accordingly.

提交回复
热议问题