How to get the multiplication of elements in a row vector by using for loop
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shuoze Xu
el 15 de Mzo. de 2022
Comentada: KSSV
el 15 de Mzo. de 2022
% create a vector
A = [-2,4,9,-5,1];
Mult = 0;
% create a for loop
for i = 1:length(A)
Mult = Mult * A(i) ;
end
% display the result
disp(Mult);
0 comentarios
Respuesta aceptada
KSSV
el 15 de Mzo. de 2022
% create a vector
A = [-2,4,9,-5,1];
Mult = 1; % <----- this should be 1
% create a for loop
for i = 1:length(A)
Mult = Mult * A(i) ;
end
% display the result
disp(Mult);
prod(A) % inbuit function
4 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!