Compute values in the nodes of a 3d matrix
1 次查看(过去 30 天)
显示 更早的评论
Hi,
Let S2 a surface below the surface S1, I would to compute values in the nodes below S2, starting from the values computed at the boundary between S1 and S2, using coefficients C2.
% Create the surfaces:
x = rand(100,1)*4 - 2;
y = rand(100,1)*4 - 2;
S1 = x.*exp(-x.^2-y.^2) * 1000;
S2 = S1 - 100;
% Create positive coefficients
C1 = 0.02 + (0.08 - 0.02).*rand(100,1);
C2 = 0.03 + (0.05 - 0.03).*rand(100,1);
% Construct the interpolant:
F1 = TriScatteredInterp(x,y,S1);
F2 = TriScatteredInterp(x,y,S2);
G1 = TriScatteredInterp(x,y,C1);
G2 = TriScatteredInterp(x,y,C2);
% Evaluate the interpolant at the locations [XI,YI].
XI = -2:0.25:2;
YI = -2:0.1:2;
[XImat,YImat] = ndgrid(XI,YI);
ZI_1 = F1(XImat,YImat);
ZI_2 = F2(XImat,YImat);
C_1 = G1(XImat,YImat);
C_2 = G2(XImat,YImat);
% Define a set of ZI locations
ZI = -500:100:500;
% Find the nodes below the surface S1 and S2
BW1 = bsxfun(@le, ZI_1, reshape(ZI,1,1,[]));
BW2 = bsxfun(@le, ZI_2, reshape(ZI,1,1,[]));
% Create a 3d grid where to compute the value in each node
[Z,Z,Z] = ndgrid(XI,YI,ZI);
% Compute value below S1 with coefficients C1
T = 18 + bsxfun(@times, C_1, Z .* BW1);
Whith the help of a file-exchange find_ndim, I've found the index where the surface S2 starts.
index = find_ndim(BW2,3,'first')
T = ???? + bsxfun(@time, C2, Z .* BW2);
Thanks for any suggestion, Gianluca
采纳的回答
Andrei Bobrov
2012-9-19
d = cumsum(BW2(:,:,end:-1:1),3);
index = bsxfun(@eq,sum(BW2,3) - 1,d(:,:,end:-1:1) - cumsum(BW2,3));
T2 = T.*index + bsxfun(@times, C_2, Z .* BW2);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!