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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com