How to modify loop code for 3D data?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
For 2D data when sizes or dimensions of v1, v2, r are 116 227, I used following code to compute data:
ti = 1 * 116
dt = ti(2)-ti(1);
nt = 116;
f0 = 30; %t = TWT;
t0 = 2/f0;
[wa,t] = wvlt(f0, t0, nt, dt);
w = w.'; t0_i = floor(t0/dt);
time = ti;
w = repmat(w, 1, 227);
%% Angles
ang = [15 30 45];
TH = ang*pi/180;
%% Forward model
for i = 1:size(v1,2)
for k = 1:length(TH)
data{i,k} = fwmod_v(v1(:,i),v2(:,i),r1(:,i),TH(k),w,t0,dt);
end
end
Now I want to modify the cde for 3D data of size
v1 = 176 139 48 i.e. 176 numb of vertical layers, 139 is horizontal traces and 48 are vertical slice each has 176 layers and 139 traces.
v2 = 176 139 48
r = 176 139 48
For 3D case how I can modify the above code?
Function
function [syn] = fwmod_v(v1,v2,r,TH,w,t0,dt)
t0_i = floor(t0/dt);
Nl = length(v1);
trc = AKR(v1,2s,r,TH);
syn = conv2(w, trc);
syn = syn(1+t0_i:Nl+t0_i,:);
function Rpp = AKR(v1, v1, r, TH)
Nt = length(v1);
Nth = length(TH);
R = zeros(Nt,Nth);
sin2 = sin(TH).^2;
tan2 = tan(TH).^2;
for i = 1:Nt-1
dvp = v1(i+1) - v1(i);
dvs = v2(i+1) - v2(i);
drho = r(i+1) - r(i);
vpm = (v1(i+1) + v1(i))/2;
vsm = (v1(i+1) + v1(i))/2;
rhom = (r(i+1) + r(i))/2;
R(i,:) = 0.5*(1 + (tan2)).*(dvp/vpm) - 4*(((vsm/vpm)^2)*dvs/vsm).*sin2 + 0.5*(1 -4*((vsm/vpm)^2).*sin2)*(drho/rhom);
end
2 Commenti
Daniel
il 5 Mar 2024
I don't think there's enough information here to answer the question. AKR isn't a standard MATLAB function as far as I can tell, and there are some typos in the fwmod_v definition (e.g. "2s" is incorrect syntax). What is AKR supposed to do?
Risposte (1)
Daniel
il 5 Mar 2024
Based on what I can see, it looks like you're performing processing along one column of input data at a time. To amend that for 3D v1 and v2, you would just add a second layer to your for loop, so that you're iterating along both dimension 2 and dimension 3.
So you could add a for j = 1:size(v1,3) after your for i = ... line, and add an extra dimension to data and an additional layer of indexing to v1 and v2, such that that line becomes
data{i,j,k} = fwmod_v(v1(:,i,j),v2(:,i,j),r1(:,i,j),TH(k),w,t0,dt);
Does that work syntactically and do what you need?
2 Commenti
Daniel
il 5 Mar 2024
Modificato: Daniel
il 5 Mar 2024
@Ahmed, so you want to continue passing in a 176-element vector, then? If so, I think what I outlined above should be correct. The extra "for j = ..." line I suggested will iterate along your new "vertical slice" dimension, and then indexing v1(:,i,j) will extract a full column vector (or vertical layer). Then you'll pass the output (which should have the same dimension it had before) into your data cell array, which will now have three indices: i for your horizontal trace, then j for your vertical slice, then k for your angle. Each element in data (i.e. data{i,j,k}) will itself contain a full (scalar, vector, or matrix) output of a single fwmod_v call.
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!