Fill up submatrix along third dimension with two dimensional matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Michael Stollenwerk
am 29 Aug. 2022
Bearbeitet: Bruno Luong
am 29 Aug. 2022
Given a p by p by N array, e.g. p=3 and N=4,
x = NaN(3,3,4);
I can easily fill up the 1 by 1 by N submatrix given a "1 by 1 matrix"doing
x(1,1,:) = 1;
But what if I want to fill up the 2 by 2 by N submatrix like this
x(1:2,1:2,:) = [1 2; 3 4];
This does not work.
How could I do it elegantly?
0 Kommentare
Akzeptierte Antwort
Bruno Luong
am 29 Aug. 2022
Bearbeitet: Bruno Luong
am 29 Aug. 2022
x(1:2,1:2,:) = repmat( [1 2; 3 4], 1, 1, size(x,3));
I would love to have MATLAB indexing to behave with auto expansion, but probably many users would be unhappy and complain because of coding error becoming silence.
0 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Matrix Indexing 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!