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 CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by