Detect Changes in Variable

Hi guys,
Currently i'm trying to implement an task graph, where i will add different variables called 'task#' at specific time.
i also wanted to create a new variable called 'task_track' to detect/track the no. of task added to.
Since i'm doing it in a loop, it is hard to implement it.
Is there other methods that i could look into that i can detect the changes and update variable 'task_track' ?
for time = 1:1:last consump(time) = consump(time) + task1;
if time >= 150
consump(time) = consump(time) + task2;
end
if time >= 420
consump(time) = consump(time) - task2;
end
end

回答 (1 件)

Oleg Komarov
Oleg Komarov 2011 年 2 月 21 日

0 投票

Not really clear what you want to do but the loop can be simplified as:
time = 1:last;
consump(time) = consump(time) + task1;
idx = time >= 150 & time < 420;
consump(idx1) = consump(idx1) + task2;
Oleg

1 件のコメント

Khalid Muhd
Khalid Muhd 2011 年 2 月 23 日
Hey Oleg,
thanks for the reply and suggestion, really appreciate it.

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

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2011 年 2 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by