How can I plot value of function (dependant on 2 variables) in 3D ?

I have a function 'Fn' whose value depends on two variables, X and Y... If X=[i1,i2,i3] Y=[j1,j2,j3] Fn returns a 3x3 matrix calculating Fn(x,y) for each combination of x and y possible... How can I plot this in 3D?

 Accepted Answer

Try using surf or any of the other 3D plot functions:
Xv = [i1,i2,i3];
Yv = [j1,j2,j3];
Zm = Fn(Xv,Yv);
[Xm,Ym] = ndgrid(Xv,Yv);
surf(Xm,Ym,Zm)

1 Comment

Thanks man!!! I've been trying to figure this out since last two days!!! :') the 'ndgrid' function was the key!! Good job mate! =)

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!