フィルターのクリア

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

7 ビュー (過去 30 日間)
Shuoze Xu
Shuoze Xu 2022 年 3 月 15 日
コメント済み: KSSV 2022 年 3 月 15 日
% 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);

採用された回答

KSSV
KSSV 2022 年 3 月 15 日
% 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 件のコメント
Shuoze Xu
Shuoze Xu 2022 年 3 月 15 日
Ok,bro.
That my first time to use that, i do not know i need to touch the accepting and voting.
KSSV
KSSV 2022 年 3 月 15 日
@Shuoze Xu No problem..... :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by