For loop for inputting some discontinous numbers

2 ビュー (過去 30 日間)
mirewuti muhetaer
mirewuti muhetaer 2020 年 1 月 31 日
コメント済み: Star Strider 2020 年 1 月 31 日
Hi,
I am trying to write a for loop on matlab such that the input is not some continous values. for example:
********************************
c=2.5;
for m=1, 1.2, 10
a=c*m;
end
*********************
is it possible to give inputs like above to for loop?
Thanks.

採用された回答

Star Strider
Star Strider 2020 年 1 月 31 日
The code you posted is a good start, however it will not work.
This version of it will:
c = 2.5;
m = [1, 1.2, 10]; % Create Vector Of Values
for k = 1:numel(m)
a(k) = c*m(k);
end
It is necessary to create an array from ‘m’ in order to work with it. The loop then uses each element of ‘m’ to create individual elements of ‘a’.
MATLAB offers more efficient ways to do this sort of calculation, however this loop will work.
  2 件のコメント
mirewuti muhetaer
mirewuti muhetaer 2020 年 1 月 31 日
Thanks so much!!
Star Strider
Star Strider 2020 年 1 月 31 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

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