Info

This question is closed. Reopen it to edit or answer.

For loop combo troubles

1 view (last 30 days)
Cary
Cary on 9 Oct 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
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

Answers (1)

Walter Roberson
Walter Roberson on 9 Oct 2015
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

This question is closed.

Tags

Products

Community Treasure Hunt

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

Start Hunting!