Plot 3D binary matrix as surface (or how to get 3D matrix coordinates)

Hi! I got a binary 650x512x128 matrix (Let's say it's called A) that represents 128 images of a curve segmentation of size 650x512 that I want to plot as a continuous surface.
I tried using isosurface, but it seems like a scattered points that doesn't make contact between each other, so that ain't look like a surface.
I tried also to get coordinates of all points and then plot using plot3 and it works, but points are not conected, here is my code:
[x,y,z] = ndgrid(1:size(A, 1), 1:size(A, 2), 1:size(A, 3)); %get coordinates of all points
xx = x(A == 1); %keep only coordinates for A == 1
yy = y(A == 1); %these 3 lines also reshape the 3d array
zz = z(A == 1); %into column vectors
plot3(xx, yy, zz, '-');
Thanks in advance to everyone.
EDIT: I've attached the test.mat file that includes the 3D matrix.

6 comentarios

try function 'surf'. You seems to plot each column seperatly, with surf you can plot one surface.
I tried also that function, but as xx, yy, and zz are vectors I get the "Z must be a matrix, not a scalar or vector" message. I've attached the .mat file which contains the 3D matrix.
Ok, i get it now. One solution (which might not be very efficient) would be to use interpolation of the zz values, using scattered interpolation.
something like the example "seamount" here:
Actually xx, yy and zz are not column vectors, but arrays of the same size as A.
Following code will at least get you closer. I thought about getting you further, but this is all i got so far:
[x,y,z] = ndgrid(1:size(V, 1), 1:size(V, 2), 1:size(V, 3)); %get coordinates of all points
xx = reshape(x(V == 1),[],1); %keep only coordinates for V == 1
yy = reshape(y(V == 1),[],1); %these 3 lines also reshape the 3d array
zz = reshape(z(V == 1),[],1); %into column vectors
figure
plot3(xx,yy,zz,'.','markersize',1)
Are you looking for slice?
Maybe the answer provided by you guys wasn't the right one, but you helped me to clarify some things. I found the answer using the following code based no the one provided by Sargondjani.
[x,y,z] = ndgrid(1:size(V, 1), 1:size(V, 2), 1:size(V, 3)); %get coordinates of all points
xx = reshape(x(V == 1),[],1); %keep only coordinates for V == 1
yy = reshape(y(V == 1),[],1); %these 3 lines also reshape the 3d array
zz = reshape(z(V == 1),[],1); %into column vectors
T = table(xx,yy,zz);
f = fit([T.zz, T.yy],T.xx,'linearinterp');
plot(f)
Thanks a lot!

Iniciar sesión para comentar.

Respuestas (0)

Preguntada:

el 30 de Jun. de 2020

Editada:

el 2 de Jul. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by