Anurag Gandhi
Anurag Gandhi

Reputation: 19

3D Surface plot for a function P(X,Y,Z)

I have a matrix of the form

X, Y, Z, P   
1, 2, 3, 2
5, 3, 5, 2
1, 2, 4, 5

and so on...

It basically represents a surface in X,Y,Z where P(X,Y,Z) is the Pressure distribution over it. I am looking to create a 3D surface plot (or any other type of plot) of it in MATLAB, but MATLAB typically requires a 2X2 Matrix for the Z values with X & Y being represented by rows and columns which would mean Z(X,Y) and which is different from what I need to plot here.

So, I am really confused on how to proceed here with the 3D surface functions in MATLAB and would really appreciate any help i can get with regards to it.

Thanks in advance!

Upvotes: 1

Views: 221

Answers (1)

Wolfie
Wolfie

Reputation: 30101

You can use the colour parameter of the scatter3 function

scatter3(X,Y,Z,[],P);

You don't have enough data to use a surface (surf) plot, as you would need the Z coordinates for every combination of X and Y. These X and Y could be gained, for instance, using meshgrid.

Upvotes: 1

Related Questions