# HG changeset patch # User Rik # Date 1305481830 25200 # Node ID 2783fa95cab719bdda35c690ca67c12303c11752 # Parent 9493880928c8d4a881ec19ff67d4e37d32b10245 Use common code idiom for creating cell array for indexing ND-arrays * int2str.m, interpft.m, num2str.m, postpad.m, prepad.m, shift.m, fftshift.m, ifftshift.m, unwrap.m diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/int2str.m --- a/scripts/general/int2str.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/int2str.m Sun May 15 10:50:30 2011 -0700 @@ -55,10 +55,7 @@ nd = ndims (n); nc = columns (n); if (nc > 1) - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx(2) = 1; ifmt = get_fmt (n(idx{:}), 0); idx(2) = 2:sz(2); diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/interpft.m --- a/scripts/general/interpft.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/interpft.m Sun May 15 10:50:30 2011 -0700 @@ -76,10 +76,8 @@ k = floor (m / 2); sz = size (x); sz(1) = n * inc - m; - idx = cell (nd, 1); - for i = 2:nd - idx{i} = 1:sz(i); - endfor + + idx = repmat ({':'}, nd, 1); idx{1} = 1:k; z = cat (1, y(idx{:}), zeros (sz)); idx{1} = k+1:m; diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/num2str.m --- a/scripts/general/num2str.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/num2str.m Sun May 15 10:50:30 2011 -0700 @@ -111,10 +111,7 @@ nd = ndims (x); perm = fix ([1:0.5:nc+0.5]); perm(2:2:2*nc) = perm(2:2:2*nc) + nc; - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{2} = perm; x = horzcat (real (x), imag (x)); x = x(idx{:}); diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/postpad.m --- a/scripts/general/postpad.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/postpad.m Sun May 15 10:50:30 2011 -0700 @@ -73,10 +73,7 @@ d = sz (dim); if (d >= l) - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{dim} = 1:l; y = x(idx{:}); else diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/prepad.m --- a/scripts/general/prepad.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/prepad.m Sun May 15 10:50:30 2011 -0700 @@ -73,10 +73,7 @@ d = sz (dim); if (d >= l) - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{dim} = d-l+1:d; y = x(idx{:}); else diff -r 9493880928c8 -r 2783fa95cab7 scripts/general/shift.m --- a/scripts/general/shift.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/general/shift.m Sun May 15 10:50:30 2011 -0700 @@ -60,10 +60,7 @@ d = sz (dim); - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); if (b >= 0) b = rem (b, d); idx{dim} = [d-b+1:d, 1:d-b]; diff -r 9493880928c8 -r 2783fa95cab7 scripts/signal/fftshift.m --- a/scripts/signal/fftshift.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/signal/fftshift.m Sun May 15 10:50:30 2011 -0700 @@ -58,9 +58,7 @@ sz = size (x); sz2 = ceil (sz(dim) / 2); idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{dim} = [sz2+1:sz(dim), 1:sz2]; retval = x(idx{:}); else diff -r 9493880928c8 -r 2783fa95cab7 scripts/signal/ifftshift.m --- a/scripts/signal/ifftshift.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/signal/ifftshift.m Sun May 15 10:50:30 2011 -0700 @@ -45,10 +45,7 @@ nd = ndims (x); sz = size (x); sz2 = floor (sz(dim) / 2); - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{dim} = [sz2+1:sz(dim), 1:sz2]; retval = x(idx{:}); else diff -r 9493880928c8 -r 2783fa95cab7 scripts/signal/unwrap.m --- a/scripts/signal/unwrap.m Sun May 15 08:58:49 2011 -0700 +++ b/scripts/signal/unwrap.m Sun May 15 10:50:30 2011 -0700 @@ -71,10 +71,7 @@ ## Take first order difference to see so that wraps will show up ## as large values, and the sign will show direction. - idx = cell (); - for i = 1:nd - idx{i} = 1:sz(i); - endfor + idx = repmat ({':'}, nd, 1); idx{dim} = [1,1:m-1]; d = x(idx{:}) - x;