I have a for loop code to calculate matrix multiplication. What is missing?

1 回表示 (過去 30 日間)
Britney
Britney 2014 年 11 月 9 日
コメント済み: Britney 2014 年 11 月 9 日
I want to create a code that calculates y=A*x for two matrices. I wrote a code from how a school book suggested and I'm stuck and don't now where to go from here. I get s=0 four times in a row. The dimensions are right but obviously not the answer. I have defined A and x but nothing is happening. What am I doing wrong?
A=[1 5 9;2 6 10;3 7 11;4 8 12];
x=[1;1;1];
y=zeros(4,1);
for i=1:4
s=0
for j=1:3
s=s+A(i,j)*x(j);
end
y(i)=s;
end

採用された回答

Matt J
Matt J 2014 年 11 月 9 日
Just add a semicolon to this line
s=0
The code is working fine, otherwise.
  1 件のコメント
Britney
Britney 2014 年 11 月 9 日
Ahh the semicolon trap it was. Thank you for the quick answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by