From: stpatryck on
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???
From: James Tursa on
stpatryck <stpatryck(a)gmail.com> wrote in message <ec15a73f-76ad-4291-a568-b615d121e464(a)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
From: SaintPatrick on
On Sep 14, 4:22 am, "James Tursa"
<aclassyguy_with_a_k_not_...(a)hotmail.com> wrote:
> stpatryck <stpatr...(a)gmail.com> wrote in message <ec15a73f-76ad-4291-a568-b615d121e...(a)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.
From: James Tursa on
SaintPatrick <patrickmyu(a)gmail.com> wrote in message <45341af6-364d-45e0-bcc2-3536c8ae52fe(a)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
From: stpatryck on
On Sep 18, 1:01 am, "James Tursa"
<aclassyguy_with_a_k_not_...(a)hotmail.com> wrote:
> SaintPatrick <patrick...(a)gmail.com> wrote in message <45341af6-364d-45e0-bcc2-3536c8ae5...(a)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