MATLAB: How to multiply matrices using for loops

for loophomeworkmatricesmatrix multiplication

I have a problem in which I have to multiply two matrices, x (700×900) and y(900,1100), using a for loop. I'm not sure where to start, I've only been using MATLAB for about a month. Any advice/help/suggestions would be great!
Thank You

Best Answer

Try this:
x = randi(9, 700, 900); % Sample data.
y = randi(9, 900, 1100);
[rowsx, colsx] = size(x);
[rowsy, colsy] = size(y);
theMatrixProduct = zeros(rowsx, colsy);
for row = 1 : rowsx
row % Print progress to command window.
for col = 1 : colsy
theSum = 0;
for k = 1 : colsx
theSum = theSum + x(row, k) * y(k, col);
end
theMatrixProduct(row, col) = theSum;
end
end