Info

此问题已关闭。 请重新打开它进行编辑或回答。

For loop combo troubles

1 次查看(过去 30 天)
Cary
Cary 2015-10-9
关闭: MATLAB Answer Bot 2021-8-20
I have the following code: When i switches to 2 how can I make j pickup where it last left off (non-nan)? For example, when i is 1, the last non-nan value is when j = 5. So when i switches to 2, how can I make j start at 6 (instead of starting at the total beginning)?
for i = 1:4
for j = 1:14
try
shortIdx(j,i)=find(mid>=.20 & mid<=.30 & expiration==xDates(i) & option_type=='c' & sym==1 & quote_date==sellDate(j),1);
longIdx(j,i)=find(ask_eod<=.05 & expiration==xDates(i) & option_type=='c' & sym==1 & quote_date==sellDate(j),1);
catch
warning('Nothing there')
shortIdx(j,i)=nan;
longIdx(j,i)=nan;
end
end
end

回答(1 个)

Walter Roberson
Walter Roberson 2015-10-9
start_j = 0;
for i = 1:4
for j = start_j + 1:14
try
shortIdx(j,i)=find(mid>=.20 & mid<=.30 & expiration==xDates(i) & option_type=='c' & sym==1 & quote_date==sellDate(j),1);
longIdx(j,i)=find(ask_eod<=.05 & expiration==xDates(i) & option_type=='c' & sym==1 & quote_date==sellDate(j),1);
start_j = j;
catch
warning('Nothing there')
shortIdx(j,i)=nan;
longIdx(j,i)=nan;
end
end
end

此问题已关闭。

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by