Thread Subject: strange error message

Subject: strange error message

From: stpatryck

Date: 14 Sep, 2009 08:03:02

Message: 1 of 9

Hello Folks,

I typed in these commands:
>> t=0:0.01:2*pi;s=t;
>> x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
>> surf(x,y,z)

I got the following error message:

??? Error using ==> surf at 78
Z must be a matrix, not a scalar or vector.


What am I doing wrong???

Subject: strange error message

From: James Tursa

Date: 14 Sep, 2009 08:22:02

Message: 2 of 9

stpatryck <stpatryck@gmail.com> wrote in message <ec15a73f-76ad-4291-a568-b615d121e464@v36g2000yqv.googlegroups.com>...
> Hello Folks,
>
> I typed in these commands:
> >> t=0:0.01:2*pi;s=t;
> >> x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
> >> surf(x,y,z)
>
> I got the following error message:
>
> ??? Error using ==> surf at 78
> Z must be a matrix, not a scalar or vector.
>
>
> What am I doing wrong???

Amazingly enough, the error message means exactly what it says! Your x and y inputs to surf form a mesh, and z forms the height at each mesh point. i.e., each combination of an x element and a y element needs to have a z element. So if x is an n-vector and y is an m-vector, then Z needs to be a m-by-n matrix.

James Tursa

Subject: strange error message

From: SaintPatrick

Date: 18 Sep, 2009 03:11:58

Message: 3 of 9

On Sep 14, 4:22 am, "James Tursa"
<aclassyguy_with_a_k_not_...@hotmail.com> wrote:
> stpatryck <stpatr...@gmail.com> wrote in message <ec15a73f-76ad-4291-a568-b615d121e...@v36g2000yqv.googlegroups.com>...
> > Hello Folks,
>
> > I typed in these commands:
> > >> t=0:0.01:2*pi;s=t;
> > >> x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
> > >> surf(x,y,z)
>
> > I got the following error message:
>
> > ??? Error using ==> surf at 78
> > Z must be a matrix, not a scalar or vector.
>
> > What am I doing wrong???
>
> Amazingly enough, the error message means exactly what it says! Your x and y inputs to surf form a mesh, and z forms the height at each mesh point. i.e., each combination of an x element and a y element needs to have a z element. So if x is an n-vector and y is an m-vector, then Z needs to be a m-by-n matrix.
>
> James Tursa

I don't understand -- z shows up in the workspace as a matrix with the
same dimensions as x and y. Since t is a matrix, z = sin(t) should
also be a matrix.

Subject: strange error message

From: James Tursa

Date: 18 Sep, 2009 05:01:04

Message: 4 of 9

SaintPatrick <patrickmyu@gmail.com> wrote in message <45341af6-364d-45e0-bcc2-3536c8ae52fe@g6g2000vbr.googlegroups.com>...
>
> I don't understand -- z shows up in the workspace as a matrix with the
> same dimensions as x and y. Since t is a matrix, z = sin(t) should
> also be a matrix.

>> t=0:0.01:2*pi;s=t;
>> x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
>> whos
  Name Size Bytes Class
  s 1x629 5032 double array
  t 1x629 5032 double array
  x 1x629 5032 double array
  y 1x629 5032 double array
  z 1x629 5032 double array

So why do you think t and z should be matrices? Clearly t is a vector, and z is a vector also because it is sin of a vector.

James Tursa

Subject: strange error message

From: stpatryck

Date: 20 Sep, 2009 21:49:31

Message: 5 of 9

On Sep 18, 1:01 am, "James Tursa"
<aclassyguy_with_a_k_not_...@hotmail.com> wrote:
> SaintPatrick <patrick...@gmail.com> wrote in message <45341af6-364d-45e0-bcc2-3536c8ae5...@g6g2000vbr.googlegroups.com>...
>
> > I don't understand -- z shows up in the workspace as a matrix with the
> > same dimensions as x and y.  Since t is a matrix, z = sin(t) should
> > also be a matrix.
> >> t=0:0.01:2*pi;s=t;
> >> x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
> >> whos
>
>   Name      Size                    Bytes  Class
>   s         1x629                    5032  double array
>   t         1x629                    5032  double array
>   x         1x629                    5032  double array
>   y         1x629                    5032  double array
>   z         1x629                    5032  double array
>
> So why do you think t and z should be matrices? Clearly t is a vector, and z is a vector also because it is sin of a vector.
>
> James Tursa

Sorry, my bad, I meant "vector" instead of matrix. I should have been
more specific. A vector is a 1 x n or n x 1 matrix. (Feel free to
correct me if I'm mistaken.)

Nevertheless, all of the variables have the same dimensions, so why
the error message?


t=0:0.01:2*pi;s=t;
 x=cos(t).*cos(s);y=cos(t).*sin(s);z=sin(t);
surf(x,y,z)

??? Error using ==> surf at 78
Z must be a matrix, not a scalar or vector.


Patrick

Subject: strange error message

From: Matt Fig

Date: 20 Sep, 2009 22:04:01

Message: 6 of 9

stpatryck <stpatryck@gmail.com> wrote in message <02e88d83-1feb-
> Nevertheless, all of the variables have the same dimensions, so why
> the error message?



You are not listening either to us or MATLAB. The criteria is NOT that the variables have the same dimensions! Is THAT what the error message says? No. Read it again, and read the doc for surf, there is an example in the documentation. Copy and paste the example, then look at the output from whos.

doc surf % READ IT.

Subject: strange error message

From: Tom

Date: 16 Oct, 2009 21:06:03

Message: 7 of 9

"Matt Fig" <spamanon@yahoo.com> wrote in message <h968sh$evd$1@fred.mathworks.com>...
> stpatryck <stpatryck@gmail.com> wrote in message <02e88d83-1feb-
> > Nevertheless, all of the variables have the same dimensions, so why
> > the error message?
>
>
>
> You are not listening either to us or MATLAB. The criteria is NOT that the variables have the same dimensions! Is THAT what the error message says? No. Read it again, and read the doc for surf, there is an example in the documentation. Copy and paste the example, then look at the output from whos.
>
> doc surf % READ IT.

I'm surprised by the lack of empathy in these replies. Isn't this a help forum? Why scan and post answers to threads asking for help, but make the asker feel like an idiot with replies like "READ IT" or "amazingly, just what it says!"?? Clearly MATLAB isn't as easy as you make it out to be if there's a site devoted to answering questions about the product!!!

It's unfortunate if you both were made to feel inferior during your formative education if you asked a question someone else perceived as remedial. But get over it and show others who know less some courtesy.

Subject: strange error message

From: dpb

Date: 16 Oct, 2009 23:10:30

Message: 8 of 9

Tom wrote:
> "Matt Fig" <spamanon@yahoo.com> wrote in message
> <h968sh$evd$1@fred.mathworks.com>...
>> stpatryck <stpatryck@gmail.com> wrote in message <02e88d83-1feb-
>>> Nevertheless, all of the variables have the same dimensions, so
>>> why the error message?
>>
>>
>> You are not listening either to us or MATLAB. The criteria is NOT
>> that the variables have the same dimensions! Is THAT what the
>> error message says? No. Read it again, and read the doc for surf,
>> there is an example in the documentation. Copy and paste the
>> example, then look at the output from whos.
>>
>> doc surf % READ IT.
>
> I'm surprised by the lack of empathy in these replies. Isn't this a
> help forum? Why scan and post answers to threads asking for help,
> but make the asker feel like an idiot with replies like "READ IT" or
> "amazingly, just what it says!"?? Clearly MATLAB isn't as easy as
> you make it out to be if there's a site devoted to answering
> questions about the product!!!
...
Well, the very first response told OP _exactly_ what was wrong and
included the needed dimensions.

c.s-s.m culture is pretty much a "help to learn" mentality as opposed to
force-feed. It's expected the learner/asker will do their part, too,
and there seems to be a certain lack here of following direction.

OP--

ML means a 2D array when it says "matrix" and explicitly notes that a
vector isn't. An [nx1] (or [1xn]) doesn't qualify, either even though
there are 2-dimensions; it must be mxn of the vector size.

see meshgrid

--

Subject: strange error message

From: Matt Fig

Date: 19 Oct, 2009 16:55:19

Message: 9 of 9

"Tom " <slustu7@gmail.com> wrote in message
> I'm surprised by the lack of empathy in these replies. Isn't this a help forum? Why scan and post answers to threads asking for help, but make the asker feel like an idiot with replies like "READ IT" or "amazingly, just what it says!"?? Clearly MATLAB isn't as easy as you make it out to be if there's a site devoted to answering questions about the product!!!

There is a difference between a lack of empathy and exasperation. The OP was told exactly what the problem was, by other posters and MATLAB itself. The fact that the OP wasn't getting this point is why I said, "READ IT."
You see, this is emphasis is not derision. When someone doesn't get something, you emphasize the important part for them.

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
osmiumite Matt Fig 20 Sep, 2009 18:07:04
surf Sprinceana 14 Sep, 2009 04:29:51
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