Problems with time travel. A (t)=Variable(t-2)

I want to make one value of a variable in a for loop dependent on the value of another variable 2 timesteps ago.
When I am on t=1, the code will lookup Variable(-1) which is an invalid index number because array index numbers must start at 1.
Is there a way to say?
if variable(x) has an invalid reference number do y?
Can you please give me an example?

1 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 2 日
編集済み: Azzi Abdelmalek 2012 年 11 月 2 日
what is the value of y(-1). give an example

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

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 11 月 2 日
編集済み: Azzi Abdelmalek 2012 年 11 月 2 日

0 投票

eg
y=[0 rand(1,20)]
use
y(max(1,n-n0))
Michael
Michael 2012 年 11 月 2 日

0 投票

This is a simplified version of my problem.
for(t=1:10),
Array1=[1 4 5 6 7 8 9]; Variable=(Array1(t-1))
end
The error is: Attempted to access Array1(0); index must be a positive integer or logical.
I want Variable to simply skip t's or return some specific value where the index is bad

カテゴリ

ヘルプ センター および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

質問済み:

2012 年 11 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by