フィルターのクリア

increasing index in for loop

4 ビュー (過去 30 日間)
Shekha
Shekha 2014 年 8 月 4 日
回答済み: Nir Rattner 2014 年 8 月 4 日
ind=[25 89 42]
p2=2*pi*t
for i=1:192
if (i > ind)
p3(i)=2*pi-p2(i);
else
p3(i)=p2(i);
end
end
I need to compare sample(1:64) with ind(1), sample(65:128) with ind(2),sample(129:192) with ind(3)

回答 (1 件)

Nir Rattner
Nir Rattner 2014 年 8 月 4 日
There are a few ways you can do this include if-else statements or switch-case statements to determine which value to choose to compare based on the current value of “i” in the loop. However, a more elegant way to do this in your case is simply dividing the value of “i” to map it to the correct index of your “ind” array. The following code should give you the correct value at any point of the loop:
ind(ceil(i) / 64)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by