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 visualización (últimos 30 días)
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 comentario
Steven Lord
Steven Lord el 3 de Jul. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Voss
Voss el 2 de Jul. de 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

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by