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

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

12 Comments

t is number of row and k is number of column sorry
I have no idea what you want to do. Why not provide a simple example. How are you applying indices to X? Is it just a simple substitution or are you applying some sort of equation.
Thank you for your interest.
I want to bootstrap the series  « data » and « X » (thirty drawns). That is why I have created the matrice Indices.
Example? Show a sample data set and what your expected output would be.
I have attached the workfile above. I would like to apply the « indices » to all columns of X and data in order to get a new matrix (6 columns and 173 rows).
The indices matrix is the bootstrapped series I want to apply to the dataset
How are you want it applied? I still don't understand.
Again, people are waiting for an example. Can you give a small example, like with only 10 rows of the two input matrices, and the desired output matrix right here in your message (not in a .mat file so we can see it here immediately). We may just give up trying to help if you continue to not provide an example here of the output you want. Sorry, but it's confusing, not just to me but to all others also.
Examples of confusion:
"I want to apply to the second column of a matrix X" What the heck does that mean? "Apply"????
I'm sure once you provide a simple example it will get answered quickly.
Thank you I will give you an exemple tonight
Ben Ked's comment moved here:
Here an example:
data =
5 (z)
6 (p)
7 (r)
x =
7 3 (z)
6 9 (p)
2 4 (r)
indices =
2 (p) 1 2
3 (r) 2 1
1 (z) 3 3
vector = [data x]
% (p) = 2 because it corresponds to position row2 of each column
g = vector(indices)
% g Output desired : indices give the position to pick in each matrix/vector
6 6 9 (p) 5 7 3 6 6 9
7 2 4 (r) 6 6 9 5 7 3
5 7 3 (z) 7 2 4 7 2 4
Note: the letters within the matrices are just for labelling the rows

Sign in to comment.

 Accepted Answer

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

More Answers (2)

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)

1 Comment

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

Sign in to comment.

g=[];
[a,b]=size(indices);
for k=1:b
g=[g,vector(repmat(indices(:,k),1,b)+[0:a:(b-1)*a])];
end

1 Comment

Dear David,
Thank you for your suggestion.
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

Sign in to comment.

Asked:

on 9 Oct 2021

Commented:

on 13 Oct 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!