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.
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
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?
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.
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.
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
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
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.
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
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.