How to extend an array to a new dimension?
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sufayan Mulani
am 29 Aug. 2023
Beantwortet: Star Strider
am 29 Aug. 2023
Suppose, I have an array
a=rand(3, 4);
I want to create a new array 'b' which has [ 3, 4, 5] size, and all 2D matrix along the third dimension are equal to 'a'.
b = zeros([size(a) 5]);
for i=1:5
b(:, :, i) = a;
end
How can I do this using MATLAB functions.
0 Kommentare
Akzeptierte Antwort
Star Strider
am 29 Aug. 2023
a=rand(3, 4);
b = zeros([size(a) 5]);
for i=1:5
b(:, :, i) = a;
end
b
b2 = repmat(a, 1, 1, 5)
Both results are the same.
.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices 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!