-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinInterpMaker2.m
executable file
·50 lines (40 loc) · 1.23 KB
/
pinInterpMaker2.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%% Prepare Pin Trap Spline
%
% Prepare a matrix for splining the pin trap potential.
f = importdata('Broad322DynamicsEnergyt.dat',' ',9);
x = f.data(:,1);
y = f.data(:,2);
z = f.data(:,3);
u = f.data(:,4);
xs = sort(uniquetol(x,1e-6,'DataScale',1));
ys = sort(uniquetol(y,1e-6,'DataScale',1));
zs = sort(uniquetol(z,1e-6,'DataScale',1));
% get the datapoint spacing, used for taking derivatives later.
xsp = mode(diff(xs));
ysp = mode(diff(ys));
zsp = mode(diff(zs));
% the size of the 3D data matrices to be filled
fullsize = [length(xs) length(ys) length(zs)];
% for each x,y,z value in the COMSOL loaded x,y,z columns, check which
% linear index this corresponds to in a 3D matrix of size fullsize.
x2i = @(x) int16(1+x/xsp);
y2i = @(y) int16(1+y/ysp);
z2i = @(z) int16(1+z/zsp);
locs = sub2ind(fullsize,x2i(x),y2i(y),z2i(z));
% Now fill the matrices:
xx = zeros(fullsize);
yy = zeros(fullsize);
zz = zeros(fullsize);
uu = zeros(fullsize);
xx(locs) = x;
yy(locs) = y;
zz(locs) = z;
uu(locs) = u;
%x = -3:0.1:3;
%y = -1:0.1:1;
%z = -2.5:0.1:2.5;
%[xxx, yyy, zzz] = ndgrid(xs,ys,zs);
%uu = interpn(xx,yy,zz,vv,xxx,yyy,zzz);
uu = uu - min(uu(:));
uu = uu/10-1;
save('pininterpB.mat','uu','xs','ys','zs')