MATLAB: Get vector from a matrix ith row or column based on given dimension

column vectordimensionMATLABmatricesrow vector

Hi,
I have very simple question but couldn't find a simple answer to it:
how can i get ith row or column of a matrix acc.to given dimension value. I mean, i need such a function:
v=getroworcolumnvector(Amatrix,i,dim);
for Amatrix is 2 dimensional array, it should give a vector which is ith row of Amatrix if dim==1, or ith column of Amatrix if dim==2
Thank you,
Baris

Best Answer

c = repmat({':'},1,ndims(A));
c{dim}=i;
A(c{:})