Info
Cette question est clôturée. Rouvrir pour modifier ou répondre.
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 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Guillaume
le 8 Mai 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 commentaires
Cette question est clôturée.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!