Consider having a matrix. From this matrix I select the same number of elements from every row. Let us say that the matrix is nxn and from each row I take m elements (m<n).
I will build a mxm matrix with this selected elements. In every row I put the elements taken from the original matrix (same row index of course).
What is the best way to achieve this?
Thankyou
One way to achieve this is illustrated here. Define an array
ato play around with …This demonstrates the use of index vectors for selecting rows and columns from one matrix into another. It depends on being able to specify the vectors you want to use as indices. You could also write:
Now, if you tell us what you mean by ‘the best way’ we may be able to tell you that too !
EDIT
So I read the question again, it seems by ‘best’ you mean ‘fastest’. I’ve never been concerned to measure the speed of this sort of operation, I await with interest one of the real Matlab experts who lurk hereabouts providing a much cleverer answer than this.
Of course, the fastest way is to not build a submatrix at all, but to operate on the elements of the original matrix. Whether your algorithm can be adapted to avoid building a submatrix is unknown to me.