function Arm=mat2rm(A)
% MAT2RM(A) converts a matrix or an array of matrices to row major form.
% The input, A, is a either a matrix or a 3 dimensional array. If A is
% a 3 dimensional array, then A is considered to be a "stack" of
% matrices, so that A(:,:,1) is the first matrix, A(:,:,2), is the
% second matrix, etc. The output, AOUT, is a matrix whos rows are the
% row major representations of the matrices in A. For example the
% matrix A(:,:,4) corresponds the the row AOUT(4,:).
% $Source: /home/stpierre/cvsroot/matlab/simulink/matrix/mat2rm.m,v $
% $Revision: 1.2 $
% $Date: 2009-07-19 22:03:05 $
% Copyright (c) 2000-2009, Jay A. St. Pierre. All rights reserved.
if nargin~=1
error('mat2rm() requires one input argument');
elseif (length(size(A)) > 3 )
error(['Input must be 2-dimensional matrix or a vector of', 10, ...
'2-dimensional matrices (a 3-dimensional array).'])
end
[rows,N]=size(A(:,:,1));
for k=1:size(A,3)
for j=1:rows
first_col=((j-1)*N)+1;
Arm(k,first_col:first_col+N-1)=A(j,1:N,k);
end
end