how to multiply every element in an array?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Cem Kurukaya
el 12 de Abr. de 2022
Comentada: Voss
el 12 de Abr. de 2022
o=[3,1,9];
This is an example of array. I want to multiply them each others. For example;
3x1x9 = 27
The lenght of array could be different. How can I calculate the multiplaction with for loop.
0 comentarios
Respuesta aceptada
Voss
el 12 de Abr. de 2022
o = [3 1 9];
% no for loop:
p = prod(o);
disp(p);
% some for loop:
p = 1;
for ii = 1:numel(o)
p = p*o(ii);
end
disp(p);
2 comentarios
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!