Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Comment on meshgrid

Subject: Comment on meshgrid

From: Thomas Clark

Date: 21 Dec, 2009 11:48:03

Message: 1 of 2

All,

This isn't really a question, just a comment on the output behaviour of meshgrid().

The output is dependent not just on the number of arguments in, but also on the number of arguments out. For example, I wanted the X array which results from:

[X Y Z] = meshgrid(1:3,1:3,1:3);

However, I don't want the Y and Z variables... so I did this:

[X1] = meshgrid(1:3,1:3,1:3);

... which I thought should produce the same thing. However, I get a two-dimensional array out:

>> size(X)
ans =
     3 3 3

>> size(X1)
ans =
     3 3

Given that I have supplied three input arguments, surely the number of output arguments to meshgrid is redundant information, and shouldn't be used to determine what the output arrays are?

What does everyone think? Is this worth reporting as a bug?

Cheers for your input...

Tom Clark

Subject: Comment on meshgrid

From: Wayne King

Date: 21 Dec, 2009 12:13:05

Message: 2 of 2

"Thomas Clark" <t.clark@remove.spamcantab.net> wrote in message <hgnn9j$931$1@fred.mathworks.com>...
> All,
>
> This isn't really a question, just a comment on the output behaviour of meshgrid().
>
> The output is dependent not just on the number of arguments in, but also on the number of arguments out. For example, I wanted the X array which results from:
>
> [X Y Z] = meshgrid(1:3,1:3,1:3);
>
> However, I don't want the Y and Z variables... so I did this:
>
> [X1] = meshgrid(1:3,1:3,1:3);
>
> ... which I thought should produce the same thing. However, I get a two-dimensional array out:
>
> >> size(X)
> ans =
> 3 3 3
>
> >> size(X1)
> ans =
> 3 3
>
> Given that I have supplied three input arguments, surely the number of output arguments to meshgrid is redundant information, and shouldn't be used to determine what the output arrays are?
>
> What does everyone think? Is this worth reporting as a bug?
>
> Cheers for your input...
>
> Tom Clark

Hi Tom, I wouldn't call it a "bug" personally. If you look at the code, what is happening is that when meshgrid() finds that the number of output arguments is less than 3, it operates in a 2D mode. However, the code could easily warn to the effect that the user has specified 3 inputs and less than 3 output arguments, and that behavior could be documented better, so it's still worthwhile to report to Mathworks as a request if its something you feel would benefit other users. Just my opinion.

Wayne

Tags for this Thread

No tags are associated with this thread.

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.

Contact us