# HG changeset patch # User Jaroslav Hajek # Date 1236943125 -3600 # Node ID b37a6c27c23f9d6185e853195bbda9226b4e1d34 # Parent 3ecbc236e2e0dc9c435e2b76667715c998fc5714 simplify repmat * * * diff -r 3ecbc236e2e0 -r b37a6c27c23f scripts/ChangeLog --- a/scripts/ChangeLog Tue Mar 10 21:54:49 2009 -0400 +++ b/scripts/ChangeLog Fri Mar 13 12:18:45 2009 +0100 @@ -1,3 +1,8 @@ +2009-03-13 Jaroslav Hajek + + * general/repmat.m: Use subscript pairs rather than forming Kronecker + products. + 2009-03-11 Ben Abbott * plot/__go_draw_axes__.m: Unset the {x,y,z}ticks when initializing diff -r 3ecbc236e2e0 -r b37a6c27c23f scripts/general/repmat.m --- a/scripts/general/repmat.m Tue Mar 10 21:54:49 2009 -0400 +++ b/scripts/general/repmat.m Fri Mar 13 12:18:45 2009 +0100 @@ -74,17 +74,21 @@ x = reshape (x, m*p, n*q); endif else - aidx = size(a); - if (length(aidx) > length(idx)) - idx = [idx, ones(1,length(aidx)-length(idx))]; - elseif (length(aidx) < length(idx)) - aidx = [aidx, ones(1,length(idx)-length(aidx))]; - endif - cidx = cell (1, length (aidx)); + aidx = size (a); + ## ensure matching size + idx(end+1:length (aidx)) = 1; + aidx(end+1:length (idx)) = 1; + ## create subscript array + cidx = cell (2, length (aidx)); for i = 1:length (aidx) - cidx{i} = kron (ones (1, idx(i)), 1:aidx(i)); + cidx{1,i} = ':'; + cidx{2,i} = ones (1, idx (i)); endfor - x = a (cidx{:}); + aaidx = aidx; + # add singleton dims + aaidx(2,:) = 1; + a = reshape (a, aaidx(:)); + x = reshape (a (cidx{:}), idx .* aidx); endif endfunction