I need one of my variables in function of time zero (0) but I get an error in MATLAB saying that I need a positive number. how can I fix that?
ex: t = 0:1:1000
if t = 0 I(t) = a + b else I(t) = b - a

 採用された回答

Mischa Kim
Mischa Kim 2014 年 2 月 25 日
編集済み: Mischa Kim 2014 年 2 月 25 日

0 投票

Maria, three things:
  • The relational operator for comparison is ==.
  • Indexing in MATLAB starts at 1, rather than 0, like in other programming languages. In other words, you cannot assign a value to t(0).
  • t is a vector, so you could do, e.g., as part of a loop:
...
if t(ii) == 0
I(t(ii) + 1) = a + b
else
I(t(ii) + 1) = b - a
end

2 件のコメント

Patrik Ek
Patrik Ek 2014 年 2 月 25 日
Or simpler
t = 1:1001;
I(t) = b-a;
I(t==0) = a+b;
Maria
Maria 2014 年 2 月 25 日
Thanks so much to both of you for the promt answer. I'll try that with my code. Maria Camila

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

質問済み:

2014 年 2 月 25 日

コメント済み:

2014 年 2 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by