from
matrix_perimeter
by Athanasios Makris
Function matrix_perimeter extracts the outer elements of a matrix in a clockwise sense.
|
| [x,A]=matrix_perimeter(A)
|
function [x,A]=matrix_perimeter(A)
% Function matrix_perimeter extracts the outer elements of
% a matrix in a clockwise sense.
%
% INPUTS
% ------
% A = An n x m matrix (real or imaginary)
%
% OUTPUTS
% -------
% x = Row vector of the elements of the matrix that exist
% in the perimeter, taken in a clockwise sense
%
% A = An (n-2)x(m-2) matrix, same as input matrix, without its elements
% existed in the perimeter
% (The input matrix is decomposed within the function)
%
% COMPATIBILITY
% -------------
% Matlab 7.2 and later
%
% EXAMPLE
% -------
% >> A=magic(4)
%
% A =
%
% 16 2 3 13
% 5 11 10 8
% 9 7 6 12
% 4 14 15 1
%
% >> [x,B]=matrix_perimeter(A)
%
% x =
%
% 16 2 3 13 8 12 1 15 14 4 9 5
%
%
% B =
%
% 11 10
% 7 6
%
% Author : Athanasios Makris
% Email : makrisathanasios@netscape.net
% Date : 01.08.09 (dd/mm/yy)
% Version : 1.0
if nargin ~=1
error('Function matrix_perimeter needs one argument')
end
if ~isempty(A)
[n,m]=size(A);
if ( (n~=1) && (m~=1) )
x=[A(1,:) A(2:end,end)' A(end,[end-1:-1:1]) A(end-1:-1:2,1)' ] ;
A=A(2:end-1,2:end-1);
else
x=A(:)';
A=[];
end
else
x=[];
A=[];
end
return;
|
|
Contact us at files@mathworks.com