Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

For loop combo troubles

1 vue (au cours des 30 derniers jours)
Cary
Cary le 9 Oct 2015
Clôturé : MATLAB Answer Bot le 20 Août 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

Réponses (1)

Walter Roberson
Walter Roberson le 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

Cette question est clôturée.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by