For a matrix A (4 rows, 1000 columns). I want to group the columns of the matrix A which have the same value for the third line. so I must have sub matrix with a third row that contains the same value.
for example:
if:
A =
1 4 5 2 2 2 2 1 1 5
1 4 5 4 4 2 2 4 5 2
3 3 3 3 4 1 3 5 3 4
4 5 5 5 4 1 5 5 5 5
then
A1 =
1 4 5 2 2 1
1 4 5 4 2 5
3 3 3 3 3 3
4 5 5 5 5 5
A2 =
2 5
4 2
4 4
4 5
A3 =
2
2
1
1
the result can be in the form of a cell.
You can make the assignment in a single line using ACCUMARRAY:
With this,
out{i}contains all columns ofAwhere the third row ofAequalsi(and empty in case there is no valid column).If you want
out{i}to contain columns corresponding to the i-th smallest unique value in the third row ofA, you can use GRP2IDX from the statistics toolbox first:Here,
out{i}contains the columns corresponding tocorrespondingEntryInA(i).