%mathpiper,def="MatrixColumn"

Function("MatrixColumn",{matrix,col})
[
  Local(m);
  m:=matrix[1];

  Check(col > 0, "Argument", "MatrixColumn: column index out of range");
  Check(col <= Length(m), "Argument", "MatrixColumn: column index out of range");

  Local(i,result);
  result:={};
  For(i:=1,i<=Length(matrix),i++)
    DestructiveAppend(result,matrix[i][col]);

  result;
];

%/mathpiper




%mathpiper_docs,name="MatrixColumn",categories="User Functions;Linear Algebra"
*CMD MatrixColumn --- obtain the column of a matrix
*STD
*CALL
	MatrixColumn(matrix,column)

*PARMS
{matrix} -- a matrix
{column} -- the index of a matrix column

*DESC
Returns the column of a matrix which is specified by {column}.

*E.G.
In> A := {{1,2}, {3,4}};
Result: {{1,2},{3,4}}

In> MatrixColumn(A,1)
Result: {1,3}}

*SEE MatrixRow
%/mathpiper_docs

    %output,preserve="false"
      
.   %/output

