Eric
Eric

Reputation: 97581

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?

Upvotes: 5

Views: 13895

Answers (1)

am304
am304

Reputation: 13876

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

Upvotes: 6

Related Questions