0001 function y=nt_cell2mat(x)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 nt_greetings
0017
0018 MAXDIMS=4;
0019
0020 if ~iscell(x); error('!'); end
0021
0022
0023 if min(size(x))>1
0024 if ndims(x)>MAXDIMS; error('!'); end
0025 sz=size(x);
0026 yy={};
0027 for k=1:size(x,1)
0028 yy{k}=nt_cell2mat(x(k,:,:,:));
0029 end
0030 y=nt_cell2mat(yy);
0031 return
0032 end
0033
0034
0035 nd=0;
0036 for iTrial=1:numel(x)
0037 nd=max(nd,ndims(x{iTrial}));
0038 end
0039 if nd>MAXDIMS; error('!'); end
0040 szs=zeros(1,nd);
0041 for iTrial=1:numel(x)
0042 tmp=size(x{iTrial});
0043 szs(1:numel(tmp))=max(szs(1:numel(tmp)),tmp);
0044 end
0045
0046
0047 y=zeros([szs,numel(x)]);
0048 for iTrial=1:numel(x)
0049 sz=size(x{iTrial});
0050 sz(numel(sz)+1:nd)=1;
0051 if nd==1
0052 y(1:sz(1),iTrial)=x{iTrial};
0053 elseif nd==2
0054 y(1:sz(1),1:sz(2),iTrial)=x{iTrial};
0055 elseif nd==3
0056 y(1:sz(1),1:sz(2),1:sz(3),iTrial)=x{iTrial};
0057 elseif nd==2
0058 y(1:sz(1),1:sz(2),1:sz(3),1:sz(4),iTrial)=x{iTrial};
0059 end
0060 end
0061
0062
0063
0064 if 0
0065
0066 x{1}=randn(10);
0067 x{2}=randn(10);
0068 disp(size(nt_cell2mat(x)));
0069 end
0070 if 0
0071
0072 x{1}=randn(10);
0073 x{2}=randn(20);
0074 disp(size(nt_cell2mat(x)));
0075 end
0076 if 0
0077
0078 x{1}=randn(10,11,12);
0079 x{2}=randn(10,11,12);
0080 disp(size(nt_cell2mat(x)));
0081 end
0082 if 0
0083
0084 x{1}=randn(10);
0085 x{2}=randn(10,11,12);
0086 disp(size(nt_cell2mat(x)));
0087 end
0088 if 0
0089
0090 x{1}=diag(1:10);
0091 x{2}=diag(randn(10,1));
0092 y=nt_cell2mat(x);
0093 figure(1); clf;
0094 subplot 221
0095 nt_imagescc(x{1});
0096 subplot 222
0097 nt_imagescc(x{2});
0098 subplot 223
0099 nt_imagescc(y(:,:,1));
0100 subplot 224
0101 nt_imagescc(y(:,:,2));
0102 end
0103 if 0
0104
0105 x{1}=diag(1:10);
0106 x{2}=diag(randn(20,1));
0107 y=nt_cell2mat(x);
0108 figure(1); clf;
0109 subplot 221
0110 nt_imagescc(x{1});
0111 subplot 222
0112 nt_imagescc(x{2});
0113 subplot 223
0114 nt_imagescc(y(:,:,1));
0115 subplot 224
0116 nt_imagescc(y(:,:,2));
0117 end
0118 if 0
0119
0120 x{1,1}=randn(10);
0121 x{2,1}=randn(10);
0122 x{1,2}=randn(10);
0123 x{2,2}=randn(10);
0124 disp(size(nt_cell2mat(x)));
0125 end
0126 if 0
0127
0128 x{1,1}=randn(10);
0129 x{2,1}=randn(11);
0130 x{1,2}=randn(12);
0131 x{2,2}=randn(13);
0132 disp(size(nt_cell2mat(x)));
0133 end
0134
0135