Asked by AA
on 26 Jan 2018

Hello,

I have an implementation that involves multiplying matrices, summing them up, and storing them. It goes like this,

A = 0;

for i=1:1225

% Load operator A_i of size NxN

A_i = load('A_i.mat');

% z_i is some variable of size Nx1 that I compute in this loop

% x is some variable of size Nx1 calculated above this loop

% I have to perform some operations like these two

y_i = A_i*(z_i + x);

A = A + A_i*A_i'

end

My problem is the large amount of simulation time being consumed by the above code. Even when the operations inside the loop are efficient (let's say ~0.01mins), the entire looped implementation still consumes about ~12-13mins. Can somebody please help me out and suggest an efficient way to do this? Thanks so much!

Opportunities for recent engineering grads.

Apply Today
## 7 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528670

## AA (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528676

## Lukas (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528721

## AA (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528753

## Walter Roberson (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528899

## AA (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528961

## David Goodmanson (view profile)

## Direct link to this comment

https://fr.mathworks.com/matlabcentral/answers/379100-efficient-way-to-perform-loops-of-matrix-multiplications#comment_528997

Sign in to comment.