Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
I have 2 matrices with size (4,4) and (4,5) respectively. I want the element (2,1) in the second matrix to try all values in the first column in the first matrix and at each value, produce new matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I have 2 matrices with size (4,4) and (4,5) respectively. I want the element located at (2,1) in the second matrix to take all the values in the first column in the first matrix. How can I do this?
4 comentarios
Respuestas (2)
Guillaume
el 8 de Mayo de 2017
Probably the easiest is to replicate your B in the 3rd dimension and copy the column of A along that dimension.
A = [1:4 ; 5:8 ; 9:12 ; 13:16]
B = rand(4, 5);
newB = repmat(B, [1, 1, size(A, 1)]); %replicate B in the 3rd dimensions as many times as there are rows in A
newB(2, 1, :) = A(:, 1); %and copy 1st column of A, overwrite whatever was in B(2, 1)
You can then iterate over the pages (3rd dimension) of that newB to do whatever it is you want to do.
for page = 1 :size(newB, 3)
%do something with B(:, :, page)
end
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!