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 vue (au cours des 30 derniers jours)
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 commentaire
Steven Lord
Steven Lord le 3 Juil 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.

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 2 Juil 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

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by