how to use for loop?

15 ビュー (過去 30 日間)
sinesipho mlonyeni
sinesipho mlonyeni 2019 年 3 月 25 日
回答済み: Image Analyst 2019 年 3 月 25 日
i want to know how to perform calculations on a vector with both positive and negative numbers,
I have this vector x=[2 -5 6 7 -4 8 -5 6]
im told to use a loop to double the positive numbers but i dont know how to
extract the negative numbers and perform calculations using the for loop
what am i supposed to do?
  1 件のコメント
madhan ravi
madhan ravi 2019 年 3 月 25 日

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

回答 (1 件)

Image Analyst
Image Analyst 2019 年 3 月 25 日
In the for loop, use an if. Here's a start.
for ......
if x(.....) > 0
% If it's positive
% x(...... = 2 * .................. % Multiply by 2
end
end

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by