generating sequence number with time sampling

2 ビュー (過去 30 日間)
Nur Amalina
Nur Amalina 2020 年 4 月 8 日
コメント済み: Nur Amalina 2020 年 4 月 8 日
Hi all!
I need to update the value of a. for t=1:1000.
while there is time sampling tk which has the sequence like this [0 2 5 7 10 12 15 .... 55 57 60]
i was trying the code below. but it doesn't work. may anyone help me? thanks in advance!
for t = 1:1000
if mod(t,2)==1
p=2;
else
p=3;
end
tk(1)=0;
tk(t+1)=tk(t)+p;
if t==tk
a(x)=a(x)+1
else
a(x)=a(x)
end
end

採用された回答

Andrei Bobrov
Andrei Bobrov 2020 年 4 月 8 日
編集済み: Andrei Bobrov 2020 年 4 月 8 日
out = cumsum([0;rem(0:23,2)' + 2]);
for "t = 1:1000":
t = (1:1000);
tt = mod(t,2);
out = cumsum([0;2 + tt(2:end)]);
  1 件のコメント
Nur Amalina
Nur Amalina 2020 年 4 月 8 日
Hi Andrei thanks for your reply.
your first code works in me. but i confuse to translate the second one. may you pls explain more?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by