Clear Filters
Clear Filters

Slices through 3-D Volumes, formed by 1D-arrays

1 view (last 30 days)
f=
I have a set of 1D - arrays and values of the inequality f.
I need to build a series of slices for any of the planes of this volume. I don't know how to do this in Matlab, because the data is in vector form. Please help.
  2 Comments
KSSV
KSSV on 12 Jan 2023
Your data lies in a sphere. You can make circular planes of required radius and center.
Andrew Sol
Andrew Sol on 12 Jan 2023
Edited: Andrew Sol on 12 Jan 2023
@KSSV And if the volume is different from a regular form, from a sphere, for example, as in this case? How to build slices automatically?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Jan 2023
Nx = 50;
Ny = 51;
Nz = 52;
load f
load x
load y
load z
figure();
PointSize = 20;
scatter3(x, y, z, PointSize, f); colorbar();
minx = min(x); maxx = max(x);
miny = min(y); maxy = max(y);
minz = min(z); maxz = max(z);
xvec = linspace(minx, maxx, Nx);
yvec = linspace(miny, maxy, Ny);
zvec = linspace(minz, maxz, Nz);
[Xq, Yq, Zq] = meshgrid(xvec, yvec, zvec);
Fq = griddata(x, y, z, f, Xq, Yq, Zq);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
mask = Fq < 1/2 | Fq > 1;
Fq(mask) = nan;
figure();
sx = linspace(minx, maxx, 7);
sy = linspace(miny, maxy, 7);
sz = linspace(minz, maxz, 7);
H = slice(Xq, Yq, Zq, Fq, sx, sy, sz);
set(H, 'EdgeColor', 'none');
  2 Comments
Joe
Joe on 12 Jan 2023
Edited: Joe on 12 Jan 2023
非常に正確な計算.
Andrew Sol
Andrew Sol on 12 Jan 2023
Edited: Andrew Sol on 12 Jan 2023
Thank you for your answer. The method is good, I tested it, but what does not suit me is that some contours are formed very sloppy and rough. I suggest this way:
[X,Y,Z] = ndgrid(0:0.1:2,0:0.1:2,0:0.1:2);
F = X.^2+Y.^2+Z.^2;
idx = double((F>=1/2) & (F<=1));
idx(idx==0) = NaN;
F1=Z.*idx;
X1=X.*idx;
Y1=Y.*idx;
Z1=Z.*idx;
P = [X1(:),Y1(:),Z1(:),F1(:)];
plot3(P(:,1),P(:,2),P(:,3),'o','MarkerSize', 3);
axis square
grid on
hold on
Here the grid is formed evenly. In addition, if we look at the location of the points on the slices, we can see that the points can be placed clearly in the desired slice.
[x y] = meshgrid(0:0.1:2,0:0.1:2); % Generate x and y for XY-plane
Z2=Z1; % auxiliary data
Z2(Z2~=0.5) = NaN; % Generate data for z-slice = 0.5, for example
plot3(P(:,1), P(:,2), Z2(:),'+','MarkerSize', 5) % Plot the slice
What else I would like: draw a border around each such "slice", remove the dots inside and, if possible, project all of slices (with differentc olors) onto one plane (well, so that all slices lie on the same surface). I haven't succeeded yet, but I'm working on it.

Sign in to comment.

More Answers (0)

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!