-
Notifications
You must be signed in to change notification settings - Fork 31
/
dindeks.m
43 lines (39 loc) · 1.22 KB
/
dindeks.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
function ind=dindeks(i,d,sais)
% ind=DINDEKS(i,d,[n1 n2 n3])
%
% Returns the indices to the ith plane perpendicular to the dth dimension
% of a threedimensional array. Return everything as a linear array.
%
% INPUT:
%
% i The ith plane perpendicular to...
% d ... the dth dimension [default: 1] of a 3D array...
% sais ... of this particular size [n1 n2 n3]
%
% EXAMPLE:
%
% vec=rand(28,13,78); chex=12;
% difer(indeks( rindeks(vec,chex) ,':')-vec(dindeks(chex,1,size(vec))))
% difer(indeks(squeeze(kindeks(vec,chex)),':')-vec(dindeks(chex,2,size(vec))))
% difer(indeks(squeeze(tindeks(vec,chex)),':')-vec(dindeks(chex,3,size(vec))))
%
% SEE ALSO: RINDEKS, KINDEKS, TINDEKS, INDEKS, SQUEEZE
%
% Last modified by fjsimons-at-alum.mit.edu, 01/30/2019
defval('d',1)
% Put in the right dimensions
n1=sais(1);
n2=sais(2);
n3=sais(3);
% Check, in SV's code, with the statement
% return dnode->data[i + j*(dnode->len1) + k*(dnode->len1)*(dnode->len2)];
switch d
case 1
ind=repmat(i-n1+[1:n2]*n1,n3,1)'+repmat([0:n3-1]'*n2*n1,1,n2)';
case 2
ind=repmat(n1*(i-1)+[1:n1],n3,1)'+repmat([0:n3-1]'*n2*n1,1,n1)';
case 3
ind=repmat(n1*n2*(i-1)+[1:n1],n2,1)'+repmat([0:n2-1]'*n1,1,n1)';
end
% Now the output
ind=ind(:);