1

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!

Wolfie
  • 27,562
  • 7
  • 28
  • 55
  • does this post help you? https://stackoverflow.com/questions/45353043/2d-contourslice-in-a-3d-domain-in-matlab/45354661#45354661 Use the first part of what Shahzad Muhammad Sarwar wrote to reshape your matrix into L3d x3d y3d and z3d. those you can then feed to Matlab functions like `slice` – Gelliant Aug 25 '17 at 07:55
  • @Gelliant I am having a bit of a difficulty with the code used there. What does nx, ny and nz represent? Also, i would like to know how to select values of the same variables for my case. And the function slice, if i understand correctly, seems to be a 2D function which slices a 3D volume but what i would need for my case is a 3D surface plot. – Anurag Gandhi Aug 25 '17 at 08:03
  • This is **4D** data, you have 4 channels you're trying to plot. Do you want to plot points in 3D space (X,Y,Z) which are *coloured* by the P value? – Wolfie Aug 25 '17 at 08:33
  • @Wolfie Yes exactly, that is indeed what i am trying to do. – Anurag Gandhi Aug 25 '17 at 08:35

1 Answers1

1

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.

Wolfie
  • 27,562
  • 7
  • 28
  • 55