comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/uncell.m @ 0:e9a9cd732c1e tip

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