Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Running if loop until a specific outcome
1 回表示 (過去 30 日間)
古いコメントを表示
I have two double vectors, a and b. Both have values for each time point t. I want to run a loop where
- -for each time t,
- --if a >= 0.5 and the next value that is >=0.5 is in a, outa = outa + 1
- --if a >= 0.5 and the next value that is >=0.5 is in b, outc = outc + 1
- --if b >= 0.5 and the next value that is >=0.5 is in b, outb = outb + 1
- --if b >= 0.5 and the next value that is >=0.5 is in b, outc = outc + 1
How might I be able to do this?
3 件のコメント
回答 (1 件)
Image Analyst
2017 年 11 月 20 日
Evidently i and k are different lengths, so that when ix goes from 2 to max(length(i),length(k)), it will be too long for the shorter of those two vectors. Before the loop put this:
length(i)
length(k)
max(length(i),length(k))
Then tell me what is is when it throws the error (look in the workspace panel).
3 件のコメント
Image Analyst
2017 年 11 月 20 日
OK, so at some point, since ix runs from 2 to 219533, ix will take on the value of 48681 (one longer than i is). So when it does this
if i(ix) < k(ix) && i(ix+1) < k(ix)
which means
if i(48680) < k(48680) && i(48680+1) < k(48680)
Now i(48680+1) is i(48681). And since there is no 48681st element of (the badly named) i, it will thrown an error.
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!