Skip to content

Instantly share code, notes, and snippets.

@gidili
Created March 7, 2010 03:00
Show Gist options
  • Save gidili/324120 to your computer and use it in GitHub Desktop.
Save gidili/324120 to your computer and use it in GitHub Desktop.
function [a] = circularSubarray(A, m, n)
if isempty(A),
error('circularSubarray: isempty(A)','A is empty') ;
elseif m==n,
error('circularSubarray: m==n','first and second index are the same') ;
end
N = size(A);
N = N(2);
if m>=1 & n<=N,
a = A(m:n);
elseif m<1 & n>=1,
a = [A(N+m:N) A(1:n)];
elseif m<=N & n>N,
a = [A(m:N) A(1:n-N)];
else
error('circularSubarray: case not implemented','circular subarray cannot be resolved') ;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment