If and continue conditions
Afficher commentaires plus anciens
Hi All,
I want Matlab to provide two matrices of same length (1*25). So basically I want the loop to only run an iteration if both conditions are satisfied.
If any of T6 or T7 is shorter that 6 observations, it should skip that particular iteration for both "estimates_2010" and "estimates_2011".
I have succeeded in previous loops but different variables with this procedure, however in this loop I am ending up with a 1*25 matrix for "alpha_2010" (which I should), but ending up with af 1*23 matrix for "alpha_2011" (which is wrong). T6, T7, Carhart_t6 and Carhart_t7 is of same length and are cell variables, lags is a fixed number on 2 which is necessary in the input function "nwest". I was certain, that the "|" was an or condition, so both variable condition needed to be satisfied in order to proceed.
I am trying to do the following:
for i = 1:size(Afkast,2) % Afkast is a 12*25 matrix
if length(T6{i}) <6 | length(T7{i}) <6 % I want my if condition to evaluate both variables, if either is shorter than 6, it should be skipped.
continue
end
estimates_2010 = nwest(T6{i},Carhart_t6{i},lags); estimates_2011 = nwest(T7{i},Carhart_t7{i},lags);
alpha_2010(:,i) =estimates_2010.beta(1); alpha_2011(:,i) = estimates_2011.beta(1);
end
I have done it for multiple different variables with same conditions, however there seem to be something wrong, maybe I am misunderstanding the "|" operator.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!