Creating an augmented matrix a set of matrices

270 views (last 30 days)
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

Accepted Answer

Stephen23
Stephen23 on 2 Mar 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))
M = 6×6
1 3 0 0 0 0 0 1 0 0 0 0 1 1 1 3 0 0 1 1 0 1 0 0 0 0 1 1 1 3 0 0 1 1 0 1

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!