Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to create a surface over x-y-z coordinates?

1,545 views
Skip to first unread message

Bilal

unread,
Mar 16, 2011, 12:56:05 PM3/16/11
to
Hello,

I am very, very new to Matlab, but i need urgent help.

I have a set of 9 data points
x y z
0 0 98.6
19.81 9.71 97.64
19.81 14.5 97.62
26.92 11.88 97.5
-14.8 17.263 96.96
29.96 14.5 96.95
-14.8 19.12 96.66
-14.8 16.27 96.36
-14.8 17.263 96.26

I need to create a surface over these points.
Can someone please literally write out what i need to put into matlab
for this to be done.
Once again, this is my first time using matlab, but it seems to be the only program
which i can use.
Any help would be super nice.

Thank you.

Wayne King

unread,
Mar 16, 2011, 1:11:04 PM3/16/11
to
"Bilal " <bma...@hotmail.com> wrote in message <ilqq35$mvd$1...@ginger.mathworks.com>...

Hi Biilal, Welcome to MATLAB! Have you read the help for surf()?

If you enter
>>doc surf

I think you find exactly what you need.

Wayne

Bilal

unread,
Mar 16, 2011, 1:44:04 PM3/16/11
to
"Wayne King" <wmki...@gmail.com> wrote in message <ilqqv8$pgr$1...@ginger.mathworks.com>...

Hi wayne,
I put this into MATLAB

X=({0,19.81,19.81,26.92,-14.8,29.96,-14.8,-14.8,-14.8});
Y=({0,9.71,14.5,11.88,17.263,14.5,19.12,16.27,17.263});
Z=({98.6,97.64,97.62,97.5,96.96,96.95,96.66,96.36,96.26});
surf(X,Y,Z)

and it gave me this error message :
??? Error using ==> surf at 78
Z must be a matrix, not a scalar or vector.

the thing is, my z is not a matrix, each one of these points has an x, y and z component.

Is there anything else i can do?

Wayne King

unread,
Mar 16, 2011, 2:00:19 PM3/16/11
to
"Bilal " <bma...@hotmail.com> wrote in message <ilqst4$1qe$1...@ginger.mathworks.com>...

You are entering them as cell arrays by using the curly braces { }. Just enter your X, Y, and Z as three columns of a matrix and call surf() and that. See if that gives you what you want.

Bilal

unread,
Mar 16, 2011, 2:15:24 PM3/16/11
to
"Wayne King" <wmki...@gmail.com> wrote in message <ilqtrj$4pl$1...@ginger.mathworks.com>...

Thanks a lot for the help Wayne, i really appreciate it.

I tried what you suggested but again there seems to be a problem,
can you see if there is anything wrong in my input:

X=[0;19.81;19.81;26.92;-14.8;29.96;-14.8;-14.8;-14.8];
Y=[0;9.71;14.5;11.88;17.263;14.5;19.12;16.27;17.263];
Z=[98.6;97.64;97.62;97.5;96.96;96.95;96.66;96.36;96.26];
surf(X,Y,Z)

it returned this message:

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


Thanks again Wayne.

Wayne King

unread,
Mar 16, 2011, 2:37:05 PM3/16/11
to
"Bilal " <bma...@hotmail.com> wrote in message <ilquns$7rq$1...@ginger.mathworks.com>...

Hi Bilal, I meant to enter them as three columns of the same matrix, not as separate column vectors.
surf() expects Z to be a matrix as the documentation states. If necessary, you can use meshgrid() to obtain matrix arguments for your X and Y. But I think in your case, you probably just want to put your X,Y,and Z as columns of a matrix and pass that to surf().

Wayne

TideMan

unread,
Mar 16, 2011, 2:47:38 PM3/16/11
to
On Mar 17, 7:15 am, "Bilal " <bma...@hotmail.com> wrote:
> "Wayne King" <wmkin...@gmail.com> wrote in message <ilqtrj$4p...@ginger.mathworks.com>...
> > "Bilal " <bma...@hotmail.com> wrote in message <ilqst4$1q...@ginger.mathworks.com>...
> > > "Wayne King" <wmkin...@gmail.com> wrote in message <ilqqv8$pg...@ginger.mathworks.com>...
> > > > "Bilal " <bma...@hotmail.com> wrote in message <ilqq35$mv...@ginger.mathworks.com>...

You have a serious problem here.
surf is expecting a rectangular grid of data points, but if you plot
the x-y grid like this:
plot(X,Y,'bo')
what do you see?
What I see is a set of almost random points.
To plot the surface through these points, you need to formulate a grid
using griddata first, then use the output of that in surf.
help griddata

Bilal

unread,
Mar 16, 2011, 3:49:05 PM3/16/11
to
TideMan <mul...@gmail.com> wrote in message <68b01731-4655-49b4...@w7g2000pre.googlegroups.com>...
Is there anyway you could help me write that with the 9 points?:
(0,0,98.6)
(19.81,9.71,97.64)
(19.81,14.5,97.62)
(26.92,11.88,97.5)
(-14.8,17.263,96.96)
(29.96,14.5,96.95)
(-14.8,19.12,96.66)
(-14.8,16.27,96.36)
(-14.8,17.263,96.26)

If you have the time and capacity, i would really appreciate it,
i'm very raw with this, so even what you explained is very complicated for me.

Thanks Tideman.
Also thank you Wayne for giving me your time, I appreciate the tips.

Wayne King

unread,
Mar 16, 2011, 5:00:21 PM3/16/11
to
"Bilal " <bma...@hotmail.com> wrote in message <ilr47h$obq$1...@ginger.mathworks.com>...

Bilal, Is this all you're looking for?

X=[0,19.81,19.81,26.92,-14.8,29.96,-14.8,-14.8,-14.8]';
Y=[0,9.71,14.5,11.88,17.263,14.5,19.12,16.27,17.263]';
Z=[98.6,97.64,97.62,97.5,96.96,96.95,96.66,96.36,96.26]';
Z = [X Y Z];
surf(Z); shading('interp');
xlabel('X'); ylabel('Y'); zlabel('f(X,Y)');

Wayne

Bilal

unread,
Mar 16, 2011, 11:13:05 PM3/16/11
to
"Wayne King" <wmki...@gmail.com> wrote in message <ilr8d5$92p$1...@ginger.mathworks.com>...

Thank you very Much Wayne, i just got home, I will try that tomorrow at my school and I'll let you know of the progress.

Thanks a bunch,

Bilal.

Nima

unread,
Oct 1, 2014, 3:20:27 AM10/1/14
to
"Bilal " <bma...@hotmail.com> wrote in message <ilru81$3t3$1...@ginger.mathworks.com>...
I know it's almost 3 years late however just for the record I think this is what you should do:
tri = delaunay(x,y); %x,y,z column vectors
trisurf(tri,x,y,z);

Carlos

unread,
Feb 23, 2016, 2:13:11 PM2/23/16
to
"Junce" wrote in message <n2l40b$3in$1...@newscl01ah.mathworks.com>...
>
> > I know it's almost 3 years late however just for the record I think this is what you should do:
> > tri = delaunay(x,y); %x,y,z column vectors
> > trisurf(tri,x,y,z);
>
> I wanted to thank you for following up with this thread. Not sure how the function works, but it was exactly what I needed.

Thank you!!!

I had 3 vectors, X, Y and Z. The fucntion trisurf(tri,X,Y,X) works for me ;)

raul davila

unread,
May 15, 2016, 10:34:08 PM5/15/16
to
"Bilal " <bma...@hotmail.com> wrote in message <ilqq35$mvd$1...@ginger.mathworks.com>...
Hello
IF THE POINTS ARE CORRECT THIS IS WHAT YOU NEED

x=[0 19.81 19.81; 26.92 -14.8 29.96; -14.8 -14.8 -14.8];
y=[0 9.71 14.5; 11.88 17.263 14.5; 19.12 16.27 17.263];
z=[98.6 97.64 97.62; 97.5 96.96 96.95; 96.66 96.36 96.26];

REGARDS
surf(x,y,z)
0 new messages