3D plotting, function approximation

8 views (last 30 days)
Peter Kerekes
Peter Kerekes on 16 Oct 2017
Commented: Peter Kerekes on 16 Oct 2017
Hello !
I do have some problem with plotting 3d function.
I have 3 column vector (X1,X2,Y) (X1,X2 is the input coordinate Y is the value in (X1,X2) coordinate) Y has the same dimension as X1,X2. I wolud like to plot Y in 3D. I was trying use [A,B]=meshgrid(X1,X2) and after surf(A,B,Y) but Y has wrong dimension to use surf(). Can anybody help, how can I transform Y to have the proper dimension? (The function between (X1,X2) and Y is unknown, I now only the value of Y in the current points)
Thank you!
  2 Comments
Cam Salzberger
Cam Salzberger on 16 Oct 2017
Hello Peter,
Are X1 and X2 evenly spaced? Like:
X1 = [1 2 3 4 1 2 3 4 1 2 3 4];
X2 = [5 5 5 5 6 6 6 6 7 7 7 7];
Because that would make this really convenient. Or are the points totally randomly-placed?
Peter Kerekes
Peter Kerekes on 16 Oct 2017
Hello Cam !
Accordin to the exercise the points should be randomly selected, but maybe the evenly space is acceptable.

Sign in to comment.

Answers (1)

Cam Salzberger
Cam Salzberger on 16 Oct 2017
Hey Peter,
If the points are random, then generally you would plot them in 3-D as singular points in three dimensions:
plot3(X1, X2, Y, 'ok')
Alternatively, you can depend on Delaunay triangulation to make a surface between the points, and then display that:
tri = delaunay(X1, X2);
trisurf(tri, X1, X2, Y);
If you really want to use "surf", you could create a scatteredInterpolant, make your query points into an evenly-spaced grid, and then display that with surf. That's probably not necessary though. I would guess that delaunay and trisurf would suffice for your needs.
-Cam
  1 Comment
Peter Kerekes
Peter Kerekes on 16 Oct 2017
Hello Cam !
Thanks a lot for your help. I've tried and work well.
Peter,

Sign in to comment.

Categories

Find more on Delaunay Triangulation in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!