Adding zeros to a matrix to match the dimensions of two matrices.
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
ammara khurshid
am 27 Nov. 2017
Kommentiert: ammara khurshid
am 2 Dez. 2017
Hi ! need help to match the size of two matrices. I have two matrices of dimensions mxn and jxk. I want make mxn of size jxk by adding zeros at the end of the mxn. A of mxn dimenssion and B of jxk dimenssion. Am doing by this way:
newA=[A,zeros(size(B)]
1 Kommentar
Akzeptierte Antwort
Guillaume
am 27 Nov. 2017
newA = [A, zeros(size(A, 1), size(B, 2)-size(A, 2)); zeros(size(B, 1)-size(A, 1), size(B, 2))];
Assuming that both dimensions of B are greater than A.
0 Kommentare
Weitere Antworten (1)
James Tursa
am 27 Nov. 2017
Another way:
newA = zeros(size(B));
newA(1:size(A,1),1:size(A,2)) = A;
2 Kommentare
Guillaume
am 27 Nov. 2017
Yes, actually simpler than my answer. And in case A is not of class double:
newA = zeros(size(B), 'like', A);
Siehe auch
Kategorien
Mehr zu Embedded Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!