function [ TE ] = calcExtinctions ( D ) %calculate the mean times to extinction; TE==0 is not extinct [ nReps maxTime nPops ] = size ( D ); ME = zeros ( nReps, 1 ); %metapopulation extinction - 1=yes; 0=no TE = zeros ( nReps, 1 ); %time to metapopulation extinction for irep = 1 : nReps Dr = squeeze ( D ( irep, :, : ) ); extpops = find ( Dr ( end, : ) == 0 ); %indicies to the populations that went extinct numextpops = length ( extpops ); %number of populations that went extinct ME ( irep ) = numextpops==nPops; if ME ( irep ) %if the metapopulation went extinct - calculate the time at which it happened mpeind = find ( all ( ( Dr == 0 )' ) ); TE ( irep ) = mpeind ( 1 )+1; end end