wolffd@0
|
1 function x = uncell(x,lvl)
|
wolffd@0
|
2 % lvl >= 0: The recursion level, starting from 0, when observing the
|
wolffd@0
|
3 % cell structures of cell structures of etc. of the input data x.
|
wolffd@0
|
4 % lvl = NaN:
|
wolffd@0
|
5 % lvl = -Inf: used in display of segmented mirscalar
|
wolffd@0
|
6 if nargin < 2
|
wolffd@0
|
7 lvl = 0;
|
wolffd@0
|
8 end
|
wolffd@0
|
9 if iscell(x)
|
wolffd@0
|
10 if isempty(x)
|
wolffd@0
|
11 x = [];
|
wolffd@0
|
12 elseif length(x) == 1
|
wolffd@0
|
13 x = uncell(x{1},lvl+1);
|
wolffd@0
|
14 else
|
wolffd@0
|
15 het = 0; % Flags different kinds of structures:
|
wolffd@0
|
16 % - structures with fixed column size but variable nb of columns (het = 1)
|
wolffd@0
|
17 % - structures with variable column size but fixed nb of columns (het = 2)
|
wolffd@0
|
18 % - structures with variable column size and variable nb of columns (het = NaN)
|
wolffd@0
|
19 l = length(x(:,:,1));
|
wolffd@0
|
20 nf = size(x,3);
|
wolffd@0
|
21 z = cell(size(x));
|
wolffd@0
|
22 for i1 = 1:size(x,1)
|
wolffd@0
|
23 for i2 = 1:size(x,2)
|
wolffd@0
|
24 for i3 = 1:size(x,3)
|
wolffd@0
|
25 z{i1,i2,i3} = uncell(x{i1,i2,i3},lvl+1);
|
wolffd@0
|
26 if i1 == 1 && i2 == 1 && i3 == 1
|
wolffd@0
|
27 s = size(z{i1,i2,i3});
|
wolffd@0
|
28 elseif not(isequal(s,size(z{i1,i2,i3})))
|
wolffd@0
|
29 % A break in the homogeneity has been discovered.
|
wolffd@0
|
30 if lvl>0
|
wolffd@0
|
31 if (het == 0 || het == 2) && (s(2) == size(z{i1,i2,i3},2))
|
wolffd@0
|
32 het = 2;
|
wolffd@0
|
33 s = max(s,size(z{i1,i2,i3}));
|
wolffd@0
|
34 elseif (het == 0 || het == 1) && (s(1) == size(z{i1,i2,i3},1))
|
wolffd@0
|
35 het = 1;
|
wolffd@0
|
36 s = max(s,size(z{i1,i2,i3}));
|
wolffd@0
|
37 else
|
wolffd@0
|
38 het = NaN;
|
wolffd@0
|
39 end
|
wolffd@0
|
40 else
|
wolffd@0
|
41 het = NaN;
|
wolffd@0
|
42 end
|
wolffd@0
|
43 end
|
wolffd@0
|
44 end
|
wolffd@0
|
45 end
|
wolffd@0
|
46 end
|
wolffd@0
|
47 if isnan(het)
|
wolffd@0
|
48 x = z;
|
wolffd@0
|
49 else
|
wolffd@0
|
50 if size(s)<3
|
wolffd@0
|
51 s(3) = 1;
|
wolffd@0
|
52 end
|
wolffd@0
|
53 if (s(1)>1 || isnan(lvl)) || lvl == -Inf
|
wolffd@0
|
54 x = NaN([s(1) l*s(2) nf*s(3:end)]);
|
wolffd@0
|
55 for j = 1:nf
|
wolffd@0
|
56 for i = 1:l
|
wolffd@0
|
57 if size(z,1)>size(z,2)
|
wolffd@0
|
58 zij = z{i,1,j};
|
wolffd@0
|
59 else
|
wolffd@0
|
60 zij = z{1,i,j};
|
wolffd@0
|
61 end
|
wolffd@0
|
62 if size(zij,3) == 1
|
wolffd@0
|
63 x(1:size(z{1,i,j},1),...
|
wolffd@0
|
64 (i-1)*s(2)+1:(i-1)*s(2)+size(z{1,i,j},2),...
|
wolffd@0
|
65 j,1:size(z{1,i,j},4)) = z{1,i,j};
|
wolffd@0
|
66 elseif nf == 1
|
wolffd@0
|
67 x(1:size(z{1,i,j},1),...
|
wolffd@0
|
68 (i-1)*s(2)+1:(i-1)*s(2)+size(z{1,i,j},2),...
|
wolffd@0
|
69 :,1:size(z{1,i,j},4)) = z{1,i,j};
|
wolffd@0
|
70 end
|
wolffd@0
|
71 end
|
wolffd@0
|
72 end
|
wolffd@0
|
73 else
|
wolffd@0
|
74 x = NaN([l*s(1) s(2) nf*s(3:end)]);
|
wolffd@0
|
75 for j = 1:nf
|
wolffd@0
|
76 for i = 1:l
|
wolffd@0
|
77 if size(z,1)>size(z,2)
|
wolffd@0
|
78 zij = z{i,1,j};
|
wolffd@0
|
79 else
|
wolffd@0
|
80 zij = z{1,i,j};
|
wolffd@0
|
81 end
|
wolffd@0
|
82 if ischar(zij) && length(zij) == 1 && zij>='A' && zij <= 'G'
|
wolffd@0
|
83 %zi
|
wolffd@0
|
84 zij = zij-'A';
|
wolffd@0
|
85 end
|
wolffd@0
|
86 x((i-1)*s(1)*size(zij,1)+1:(i-1)*s(1)*size(zij,1)+size(zij,1),...
|
wolffd@0
|
87 1:size(zij,2),...
|
wolffd@0
|
88 j,...
|
wolffd@0
|
89 1:size(zij,4)) = zij;
|
wolffd@0
|
90 end
|
wolffd@0
|
91 end
|
wolffd@0
|
92 end
|
wolffd@0
|
93 end
|
wolffd@0
|
94 end
|
wolffd@0
|
95 elseif ischar(x)
|
wolffd@0
|
96 switch x
|
wolffd@0
|
97 case 'C'
|
wolffd@0
|
98 x = 0;
|
wolffd@0
|
99 case 'C#'
|
wolffd@0
|
100 x = 1;
|
wolffd@0
|
101 case 'D'
|
wolffd@0
|
102 x = 2;
|
wolffd@0
|
103 case 'D#'
|
wolffd@0
|
104 x = 3;
|
wolffd@0
|
105 case 'E'
|
wolffd@0
|
106 x = 4;
|
wolffd@0
|
107 case 'F'
|
wolffd@0
|
108 x = 5;
|
wolffd@0
|
109 case 'F#'
|
wolffd@0
|
110 x = 6;
|
wolffd@0
|
111 case 'G'
|
wolffd@0
|
112 x = 7;
|
wolffd@0
|
113 case 'G#'
|
wolffd@0
|
114 x = 8;
|
wolffd@0
|
115 case 'A'
|
wolffd@0
|
116 x = 9;
|
wolffd@0
|
117 case 'A#'
|
wolffd@0
|
118 x = 10;
|
wolffd@0
|
119 case 'B'
|
wolffd@0
|
120 x = 11;
|
wolffd@0
|
121 end
|
wolffd@0
|
122 elseif 0 %scal
|
wolffd@0
|
123 if size(x,1)==1 && size(x,2)==1 && size(x,3)>1
|
wolffd@0
|
124 x = shiftdim(x,2);
|
wolffd@0
|
125 else
|
wolffd@0
|
126 %y = zeros(size(x,2),size(x,1),size(x,3));
|
wolffd@0
|
127 %y = zeros(size(x));
|
wolffd@0
|
128 %for i = 1:size(x,3)
|
wolffd@0
|
129 % y(:,:,i) = x(:,:,i);
|
wolffd@0
|
130 %end
|
wolffd@0
|
131 %x = y;
|
wolffd@0
|
132 end
|
wolffd@0
|
133 elseif 0 %not(isnan(lvl)) && lvl>=0
|
wolffd@0
|
134 %x = squeeze(x);
|
wolffd@0
|
135 if size(x,1) == 1
|
wolffd@0
|
136 x = x(:);
|
wolffd@0
|
137 end
|
wolffd@0
|
138 elseif 0 %size(x,3) > 1 && size(x,1) == 1
|
wolffd@0
|
139 x = reshape(x,size(x,2),size(x,3))';
|
wolffd@0
|
140 end |