comparison scripts/general/repmat.m @ 8970:b37a6c27c23f

simplify repmat * * *
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 13 Mar 2009 12:18:45 +0100
parents eb63fbe60fab
children 853f96e8008f
comparison
equal deleted inserted replaced
8969:3ecbc236e2e0 8970:b37a6c27c23f
72 x = reshape (a, m, 1, n, 1); 72 x = reshape (a, m, 1, n, 1);
73 x = x(:, ones (1, p), :, ones (1, q)); 73 x = x(:, ones (1, p), :, ones (1, q));
74 x = reshape (x, m*p, n*q); 74 x = reshape (x, m*p, n*q);
75 endif 75 endif
76 else 76 else
77 aidx = size(a); 77 aidx = size (a);
78 if (length(aidx) > length(idx)) 78 ## ensure matching size
79 idx = [idx, ones(1,length(aidx)-length(idx))]; 79 idx(end+1:length (aidx)) = 1;
80 elseif (length(aidx) < length(idx)) 80 aidx(end+1:length (idx)) = 1;
81 aidx = [aidx, ones(1,length(idx)-length(aidx))]; 81 ## create subscript array
82 endif 82 cidx = cell (2, length (aidx));
83 cidx = cell (1, length (aidx));
84 for i = 1:length (aidx) 83 for i = 1:length (aidx)
85 cidx{i} = kron (ones (1, idx(i)), 1:aidx(i)); 84 cidx{1,i} = ':';
85 cidx{2,i} = ones (1, idx (i));
86 endfor 86 endfor
87 x = a (cidx{:}); 87 aaidx = aidx;
88 # add singleton dims
89 aaidx(2,:) = 1;
90 a = reshape (a, aaidx(:));
91 x = reshape (a (cidx{:}), idx .* aidx);
88 endif 92 endif
89 93
90 endfunction 94 endfunction
91 95
92 # Test various methods of providing size parameters 96 # Test various methods of providing size parameters