To Clarify, below is the code:
%Condition Matrix = [n x 2] matrix of the format as described above, look 'Dat'.
%Find the number of voyages
for i = 1:2 %number of loading conditions i.e. ballasted and laden
finite_indx = double(~isnan(Condition_Matrix(:,i))) ;
shifted_indx = [0 ; finite_indx(1:end-1) ] ;
multiplied_indx = finite_indx .* shifted_indx ;
Logical_Matrix = [ Condition_Matrix(:,i) , finite_indx , shifted_indx , multiplied_indx ] ;
Voyages_indx = sum( double(Logical_Matrix(:,2:end) == [1 0 0]),2) == 3 ;
Voyages = sum(Voyages_indx) ;
%Indexes
%Index of first data recording value of voyage
idx_low = find(sum( double(Logical_Matrix(:,2:end) == [1 0 0]),2) == 3) ;
%Index of last data recording value of voyage
idx_int = sum( double(Logical_Matrix(:,2:end) == [0 1 0]),2) == 3 ;
idx_high = find([idx_int(2:end) ; true]);
for j=1:Voyages
%Power vs. RPM Matrix of each voyage
P_mat = [P_b(idx_low(j):idx_high(j)) , RPM(idx_low(j):idx_high(j)) , Speed(idx_low(j):idx_high(j))] ;
p(j,:)={P_mat} ;
end
end