Effacer les filtres
Effacer les filtres

How to get the multiplication of elements in a row vector by using for loop

7 vues (au cours des 30 derniers jours)
Shuoze Xu
Shuoze Xu le 15 Mar 2022
Commenté : KSSV le 15 Mar 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);

Réponse acceptée

KSSV
KSSV le 15 Mar 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);
360
prod(A) % inbuit function
ans = 360
  4 commentaires
Shuoze Xu
Shuoze Xu le 15 Mar 2022
Ok,bro.
That my first time to use that, i do not know i need to touch the accepting and voting.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by