# Apply the same matrix index to another matrix (bootstrap for matrix processes)

1 view (last 30 days)
Ben Ked on 9 Oct 2021
Commented: Ben Ked on 13 Oct 2021
Hello,
I have a matrix index INDICES (t=173;k=30) I want to apply to the second column of a matrix X (t=173;k=6)
I have tried data=X(2,indices) but it doesn't work. When I code data=X(indices) I have my new matrix but with the index applied to the first column of X. The output is a data matrix (t=173;k;30) but with column data from the first column of X only
If possible I would like to get as an output the matrix where the index matrix is applied to all column (a matrix t=173; k=30*6)
I think it is simple, but I can't find the solution.
Thank you
Ben Ked on 10 Oct 2021
Note: the letters within the matrices are just for labelling the rows

Matt J on 10 Oct 2021
Edited: Matt J on 10 Oct 2021
Data=[5 7 3
6 6 9
7 2 4];
indices=[ 2 1 2
3 2 1
1 3 3];
tmp=num2cell(Data,2);
output=cell2mat(tmp(indices))
output = 3×9
6 6 9 5 7 3 6 6 9 7 2 4 6 6 9 5 7 3 5 7 3 7 2 4 7 2 4
Ben Ked on 13 Oct 2021
Thank you very much, this is exactly what I need.
Best regards,

Matt J on 9 Oct 2021
Edited: Matt J on 9 Oct 2021
I want to apply to the second column of a matrix X (t=173;k=6)...I have tried data=X(2,indices) but it doesn't work
You seem to have columns and rows mixed up. You should have,
data=X(indices,2)
Ben Ked on 9 Oct 2021
Thank you Matt J,
this gives a vector of 1 column with 5190 rows (which corresponds to 173*30). The desired outcome would be 173 rows and 30 columns.
Thank you one more time for your guidance

David Hill on 9 Oct 2021
g=[];
[a,b]=size(indices);
for k=1:b
g=[g,vector(repmat(indices(:,k),1,b)+[0:a:(b-1)*a])];
end
Ben Ked on 10 Oct 2021
Dear David,
It doesnt work, I have modified my message above to make it clearer (I hope !).
We should have nbcol of "g" = nbcol of "indices" times nbcol of "indices) --> 9 in the above exemple
Thank you once again