Apply the same matrix index to another matrix (bootstrap for matrix processes)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ben Ked
el 9 de Oct. de 2021
Comentada: Ben Ked
el 13 de Oct. de 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
12 comentarios
Matt J
el 10 de Oct. de 2021
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
Respuesta aceptada
Más respuestas (2)
David Hill
el 9 de Oct. de 2021
g=[];
[a,b]=size(indices);
for k=1:b
g=[g,vector(repmat(indices(:,k),1,b)+[0:a:(b-1)*a])];
end
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!