Creating an augmented matrix a set of matrices
59 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Liz Bradford
am 2 Mär. 2023
Beantwortet: Stephen23
am 2 Mär. 2023
Hi all,
I'm writing some code and feel like there should be a way to do this better but I am not sure how.
I want to produce a finite termination of this:

from an
matrix A where
are
matrices.
For example, I might want to make

with
.
.So far I've succefully done this with a loop. Is there a way to do it via vectorisation?
Thank you for your advice :-)
Here's my draft attempts. s tells me how many rows I want, I also do not know what k is before I start. The augmented matrix in the literature tends to be written as 𝒜hence me calling it "curlyA".
A(:,:, 1) = [1, 3; 0 1]; A(:,:, 2) = [1, 1; 1 1]; %A(:,:, 3) = [0, 0; 0 0];
[n, ~, k] = size(A);
s = 2;
curlyA = zeros(n*(s+1)); % construct augmented curly A
max_col = reshape(permute(A(:,:, 1:k),[2 1 3]),size(A,2),[])'; % make first column of curly A for this order pole
if k < size(curlyA, 1)
max_col(size(curlyA, 1), n) = 0; % if we don't have enough rows, add zeros
end
for ii = 1:s+1
curlyA((ii-1)*n+1:end, (ii-1)*n+1:ii*n) = max_col(1:((s+1)-ii+1)*n, :); % construct curly A from max_col
end
0 Kommentare
Akzeptierte Antwort
Stephen23
am 2 Mär. 2023
A = cat(3,[1,3;0,1],[1,1;1,1],[0,0;0,0]);
C = num2cell(A,1:2);
X = 1+tril(toeplitz(1:numel(C)));
C = [{zeros(2)};C(:)];
M = cell2mat(C(X))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Bartlett 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!