Using vector3d arrays

56 views
Skip to first unread message

David Mainprice

unread,
Mar 1, 2013, 3:17:13 AM3/1/13
to mtex...@googlegroups.com
Please be as detailed as possible, explain what you want to do, what kind of data you are using. Attaching simplified code and data is always useful.

a) How  can you preallocate vector3d arrays 

% is there a way to create an array of vector3d zeros
% although this does not seem to work correctly
nn=181
pSH = zeros(nn);

b) How should one correctly assign a vector3d element of array in for loop  where ps1  and  ps2 are  vector3d arrays from MTEX velocity function

for i=1:nn
% angle between SKS_prop_dirn vector and fastest S-wave polarization direction ps1
Z_to_ps11 = angle(SKS_prop_dirn,ps1(i),'antipodal')*180.0/pi
% assign SH polarization parallel or near to plane, angle with plane normal Z > 45 degrees
  if(Z_to_ps11 > 45.0)
    SH(i)=vs1(i);
    pSH(i)=ps1(i);
    SV(i)=vs2(i);
    pSV(i)=ps2(i);
  else
    SH(i)=vs2(i);
    pSH(i)=ps2(i);
    SV(i)=vs1(i);
    pSV(i)=ps1(i);
  end
end 

c) why does pSH_max have dimensions of 181 when I was expecting one vector3d ?
pSH_max = pSH(index_max);

Attached script 

Some of these MTEX constructions are not so obvious to me !

all the best David Mainprice

Olivine_single_crystal_define_tensor.m

Ralf Hielscher

unread,
Mar 1, 2013, 4:25:46 AM3/1/13
to mtex...@googlegroups.com
a) preallocation of vector3d

s = [181 1]; % size of the vector to be preallocated
v
= vector3d(zeros(s),zeros(s),zeros(s))

b) I don't see anything wrong in your code. Maybe you can make it faster and more elegant by

% compute all angles
Z_to_ps11 = angle(SKS_prop_dirn,ps1,'antipodal')*180.0/pi;

% assign SH polarization parallel or near to plane, angle with plane normal Z > 45 degrees
ind = Z_to_ps11 > 45.0; 
  
SH(ind)=vs1(ind);
pSH(ind)=ps1(ind);
SV(ind)=vs2(ind);
pSV(ind)=ps2(ind);
  
SH(~ind)=vs2(~ind);
pSH(~ind)=ps2(~ind);
SV(~ind)=vs1(~ind);
pSV(~ind)=ps1(~ind);

c) for me it works correctly.

pSV(1)

gives a single vector
Reply all
Reply to author
Forward
0 new messages