Compute values in the nodes of a 3d matrix
Show older comments
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
5 Comments
José-Luis
on 19 Sep 2012
I don't understand the question. What does ???? mean?
gianluca
on 19 Sep 2012
Sven
on 19 Sep 2012
Gianluca, can you explain more clearly the following:
"% Compute value below S1 with coefficients C1"
Also, what do you expect the size(T) of your final value T should be? We're just having a bit of trouble understanding what your final answer will look like... once we understand that, we can show you the syntax to get that answer.
gianluca
on 19 Sep 2012
gianluca
on 19 Sep 2012
Accepted Answer
More Answers (0)
Categories
Find more on Bodies in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!