How can I store and sum matrix using loop for?

Hi threre.
I have the following matrices and the code I am running to get the sum of matrices:
A = sparse matrix (20000x20000)
I = matrix identity of A
for ii = 1:200
C{ii} = A^ii;
L = I + C{ii};
end
What I would like to get as result is L = I+C{1}+C{2}+C{3}...+C{200}.
However I am getting L = I+C{200}.
Could you help me to find the mistake, please?

 采纳的回答

A = sparse matrix (20000x20000)
L = speye(size(A));
for ii = 1:200
C{ii} = A^ii;
L = L + C{ii};
end

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by