Info
This question is closed. Reopen it to edit or answer.
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 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Guillaume
on 8 May 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 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!