Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot a meshgrid in 2D?

I have this code, which takes a meshgrid, and applies a transformation to every point:

function [newx, newy] = transform(x, y)
    newx = 10 * x + y*y;
    newy = 5 * y;
end

[x, y] = meshgrid(1:5, 1:5);
[u, v] = arrayfun(@transform, x, y);

I want to plot the new mesh in 2D. The closest I can get is to do so in 3D by adding a Z component of 0:

mesh(u, v, zeros(size(u)))

3D mesh

How can I get matlab/octave to just show this plot on a 2d set of axes?

like image 603
Eric Avatar asked Oct 11 '13 13:10

Eric


People also ask

What does Meshgrid return?

meshgrid function returns two 2-Dimensional arrays representing the X and Y coordinates of all the points.

How do you define a Meshgrid in MATLAB?

Description. [ X , Y ] = meshgrid( x , y ) returns 2-D grid coordinates based on the coordinates contained in vectors x and y . X is a matrix where each row is a copy of x , and Y is a matrix where each column is a copy of y . The grid represented by the coordinates X and Y has length(y) rows and length(x) columns.


1 Answers

Maybe I'm missing the point here, but what's wrong with a simple plot(u,v,'b-x',u',v','b-x')?

enter image description here

like image 178
am304 Avatar answered Sep 19 '22 21:09

am304