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 view (last 30 days)
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 Comment
Steven Lord
Steven Lord on 3 Jul 2022
@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.

Sign in to comment.

Accepted Answer

Voss
Voss on 2 Jul 2022
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

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!