MATLAB Answers

0

Create 4D surface plot from x, y, z and c column vectors

Asked by Emmanouil Barmpounakis on 26 Jan 2017
Latest activity Commented on by Walter Roberson
on 15 Jun 2018

I have 4 columns in a table named A. The 3 columns x,y,z are the initial conditions and c is the result of a specific function I use c = f(x,y,z). I want to show the result c[i] for every case x[i],y[i],z[i] as a surface where the colour will stand for how high/low the value of c is.

I use the code below:

xx = A.x
yy = A.y
zz = A.z
cc = A.c

but the following error appears:

Z must be a matrix, not a scalar or vector.

Any ideas?

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 26 Jan 2017
 Accepted Answer

scatteredInterpolant or TriScatteredInterp. Then evaluate at a regular grid. Then you can isosurface() or slice()

  5 Comments

Thank you for your answer! I used some other functions, but your answer helped me find them. :)

This is what I used.

scatHand = scatter3(xx, yy, zz);
set(scatHand, 'CData', cc);

i do not understand the answer. Can you please send me your code or more details at least because i have exactly the same issue.

The original question had been about building a 4D surface plot; the technique for that is

xx = A.x;
yy = A.y;
zz = A.z;
cc = A.c;
F = scatteredInterpolant(xx, yy, zz, cc);
Nx = 10; Ny = 10; Nz = 10;
xv = linspace(min(xx),max(xx),Nx);
yv = linspace(min(yy),max(yy),Ny);
zv = linspace(min(zz),max(zz),Nz);
[xq, yq, zq] = ndgrid(xv, yv, zv);
cc_cuboid = F(xq, yq, zq);
Nprobe = 5;
probe_cc = linspace(min(cc), max(cc), Nprobe);  %5 isosurfaces
for K = 1 : Nprobe
  patch(isosurface(xq, yq, zq, cc_cuboid, probe_cc(K)));
end
legend( sprintf('cc = %g', probe_cc) );

Sign in to comment.