1 |
adcroft |
1.1 |
function [a] = tile(b,n) |
2 |
|
|
% a=tile(b,n); |
3 |
|
|
% |
4 |
|
|
% Extract single tile from cubed array |
5 |
|
|
% |
6 |
|
|
% b can have dimensions (M*6,M,Nr) or (M,M,Nr,6) |
7 |
|
|
% |
8 |
|
|
% n can be vector of integers between 1 and 6 |
9 |
|
|
|
10 |
|
|
|
11 |
|
|
if min(n)<1 | max(n)>6 |
12 |
|
|
disp(sprintf('n=',n)); |
13 |
|
|
error('tile: second argument n is out of range'); |
14 |
|
|
end |
15 |
|
|
|
16 |
|
|
if size(b,ndims(b))==6 |
17 |
|
|
switch ndims(b) |
18 |
|
|
case 3, |
19 |
|
|
a=b(:,:,n); |
20 |
|
|
case 4, |
21 |
|
|
a=b(:,:,:,n); |
22 |
|
|
otherwise |
23 |
|
|
error('tile: it seems that b has too many dimensions'); |
24 |
|
|
end |
25 |
|
|
elseif size(b,2)==6 |
26 |
|
|
m=size(b,1); |
27 |
|
|
k=1; |
28 |
|
|
for N=n; |
29 |
|
|
switch ndims(b) |
30 |
|
|
case 3, |
31 |
|
|
a(:,:,k)=squeeze(b(:,N,:)); |
32 |
|
|
case 4, |
33 |
|
|
a(:,:,:,k)=squeeze(b(:,N,:,:)); |
34 |
|
|
otherwise |
35 |
|
|
error('tile: it seems that b has too many dimensions'); |
36 |
|
|
end |
37 |
|
|
k=k+1; |
38 |
|
|
end |
39 |
|
|
elseif size(b,1)==size(b,2)*6 |
40 |
|
|
m=size(b,2); |
41 |
|
|
k=1; |
42 |
|
|
for N=n; |
43 |
|
|
switch ndims(b) |
44 |
|
|
case 2, |
45 |
|
|
a(:,:,k)=b((N-1)*m+1:N*m,:); |
46 |
|
|
case 3, |
47 |
|
|
a(:,:,:,k)=b((N-1)*m+1:N*m,:,:); |
48 |
|
|
otherwise |
49 |
|
|
error('tile: it seems that b has too many dimensions'); |
50 |
|
|
end |
51 |
|
|
k=k+1; |
52 |
|
|
end |
53 |
|
|
else |
54 |
|
|
disp(sprintf('Size(b) = %i %i %i %i %i %i',size(b))); |
55 |
|
|
error('tile: Size of first argument is not consistent with cubed array'); |
56 |
|
|
end |