multiply a 1 by 500 matrix to a 688 by 550 matrix and want to get the result for iteration instead of final value from 1 by 500 matrix!

1 回表示 (過去 30 日間)
for i = 1:5
r(:,:) = (ait(:,i)*podu);
end
ait is 1 by 500 matrix and podu is 688 by 550 matrix. Using this code gives me the result for the product of 5th value of ait times the podu matrix. I want to sum all the values for all the iteration and create a 688 by 550 matrix for r!
Thank you
  1 件のコメント
Steven Lord
Steven Lord 2022 年 7 月 3 日
@Kai5er flagged this as Unclear stating "I think the question is unclear and i want to remove it and will upload with better explanation"
You've already received an answer. Don't remove it and repost. Please post comments clarifying the question.

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

採用された回答

Voss
Voss 2022 年 7 月 2 日
It's not clear to me whether "all the iterations" means to iterate over the first 5 elements of ait or to iterate over all elements of ait, so the below has it both ways:
Method 1, similar to your loop:
% initialize r to be a matrix of zeros, the same size as podu
r = zeros(size(podu));
for i = 1:5 % first 5 only, or
% for i = 1:numel(ait) % all
r = r + ait(i)*podu;
end
Method 2:
% sum the ait first, then multiply the sum by podu:
r = sum(ait(1:5))*podu; % first 5 only, or
% r = sum(ait)*podu; % all

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by