Filling a 3d matrix from columns

say we create a empty 3d matrix
A= zeros(30,30,361)
I have variable Pix, a 361 x 12 double matrix, were each column is the length of 361 data point. There are 12 samples columns, How would i randomly grab each column sample and fill the zeros matrix "A" so that all 361 data points in the 12 column lay on the matrix in 1 x 1 x 361 until it has filled all 30 x 30 positions.

 Respuesta aceptada

Joseph Cheng
Joseph Cheng el 10 de Sept. de 2014
so you can use randi(12,30,30) to generate a 30x30 matrix of values 1 to 12 to select which of the 12 columns to place in the row/column location. then use for loops to go through each index and specify the column.
example:
x = rand(361,12);
randcolumn = randi(12,30,30);
A = zeros(30,30,361);
for ind = 1:30
for jnd = 1:30
A(ind,jnd,:) = x(randcolumn(ind,jnd));
end
end

1 comentario

Arjun Raja
Arjun Raja el 19 de Abr. de 2022
Kind of late but is there any way to do this without using a for loop?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Preguntada:

el 10 de Sept. de 2014

Comentada:

el 19 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by