subMtx.m 420 B

123456789101112131415161718192021
  1. % MTX = subMtx(VEC, DIMENSIONS, START_INDEX)
  2. %
  3. % Reshape a portion of VEC starting from START_INDEX (optional,
  4. % default=1) to the given dimensions.
  5. % Eero Simoncelli, 6/96.
  6. function mtx = subMtx(vec, sz, offset)
  7. if (exist('offset') ~= 1)
  8. offset = 1;
  9. end
  10. vec = vec(:);
  11. sz = sz(:);
  12. if (size(sz,1) ~= 2)
  13. error('DIMENSIONS must be a 2-vector.');
  14. end
  15. mtx = reshape( vec(offset:offset+prod(sz)-1), sz(1), sz(2) );