Thread Subject: inverse of meshgrid?

Subject: inverse of meshgrid?

From: David Doria

Date: 5 Oct, 2008 17:56:01

Message: 1 of 3

some functions, like sphere(), return data that is ready for plotting with something like mesh or surf. If I am interested in plotting the points returned by a function like this, I have done

[X Y Z] = sphere;
n = 21;
counter = 0;
for i = 1:n
    for j = 1:n
        counter = counter + 1;
        x(counter) = X(i,j);
        y(counter) = Y(i,j);
        z(counter) = Z(i,j);
    end
end

plot3(x, y, z, 'o')

Is there a better way to do this?

Thanks,
Dave

Subject: inverse of meshgrid?

From: Walter Roberson

Date: 5 Oct, 2008 20:00:27

Message: 2 of 3

David Doria wrote:
> some functions, like sphere(), return data that is ready for plotting with
> something like mesh or surf. If I am interested in plotting the points returned
> by a function like this, I have done

> [X Y Z] = sphere;
> n = 21;
> counter = 0;
> for i = 1:n
> for j = 1:n
> counter = counter + 1;
> x(counter) = X(i,j);
> y(counter) = Y(i,j);
> z(counter) = Z(i,j);
> end
> end
 
> plot3(x, y, z, 'o')

> Is there a better way to do this?

plot3(X(:), Y(:), Z(:), 'o')

Subject: inverse of meshgrid?

From: David Doria

Date: 5 Oct, 2008 20:20:19

Message: 3 of 3

hahaha yea... that'd do it, I guess the code I wrote was exactly vectorization!

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com