i=1, 2, 3,,, However, when (a-i)> 0 is calculated.

1 回表示 (過去 30 日間)
haeyeon JI
haeyeon JI 2020 年 7 月 11 日
回答済み: madhan ravi 2020 年 7 月 11 日
i=1, 2, 3,,,
However, when (a-i)> 0 is calculated.
N, a is any positive integer,
station(2+i)=(a-(a-i))*N
I am trying to make a do statement, but I get an error
I am wondering how I should write the code to run it.
for example.
if a=4
i=1 station(3)=(4-(4-1))*N
i=2 station(4)=(4-(4-2))*N
i=3 station(5)=(4-(4-3))*N
i=4 station(6)=(4-(4-4))*N %->This case is not considered. Because (a-i) <= 0 (when (a-i)> 0 is calculated.)

採用された回答

madhan ravi
madhan ravi 2020 年 7 月 11 日
clear station
a = 4
ii = 1:a-1;
N = 2; % any nunber
station(ii+2) = (4-(4-ii))*N

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2020 年 7 月 11 日
編集済み: Walter Roberson 2020 年 7 月 11 日
for i = 1 : a - 1
station(i+2) = (4-(4-i))*N;
end

John D'Errico
John D'Errico 2020 年 7 月 11 日
編集済み: John D'Errico 2020 年 7 月 11 日
Or, with no loop at all, and no test required. Just
i = 1:a-1;
station(i+2) = (4-(4-i))*N;
This will define the entire vector at once, leaving station(1) and station(2) as zero. But then you never said what they were anyway.

カテゴリ

Help Center および File ExchangeWeb Services についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by