2013-03-01 3 views
0

주가가 매우 짧은 행렬 (750000 x 6)을 가지고 있습니다. 시간 간격이 일정하지 않으므로 새로운 시간을 보간했습니다. 평일 근무 시간 중에 만 시간을 포함하기를 원하기 때문에 보간 시간이 그 안에 있는지를 확인하고 그 항목을 새 행렬에 복사하는 for 루프가 있습니다. 그러나 내 프로그램은 영원히 계속 실행됩니다 (> 10 분). , 항목이 삭제됩니다 때MATLAB에서 대형 행렬을위한 루프 최적화

A = IBM; 
times = A(:,1); 
incr = t; 
uniqday = datevec(times); 
uniqday = unique(uniqday(:,1:3), 'rows'); % unique days for data 

% Computes interpolated prices at sampling interval 
interptimes = (times(1):incr:times(end)).';  

% Fractional hours into the day 
frac_hours = 24*(interptimes - floor(interptimes));  
% Exclude interpolated times outside of trading hours 
newtimes = interptimes((frac_hours > 0) & (frac_hours < 19.1)); 

% Exclude weekends & holidays 
newtimesvec = datevec(newtimes); 
newtimesvec2 = zeros(length(newtimesvec),6); 
for j = 1:length(uniqday) 
    for i = 1:length(newtimesvec) 
     if newtimesvec(i,1:3) == uniqday(j,:) 
       newtimesvec2(i,:) = newtimesvec(i,:); 
     else  %Program always get stuck at this line 
     end 
    end 
end 

그래서 어쩌면 새로운 행렬에 빠른 대신에 복사하는 것 보간 시간 배열에서 항목을 삭제 생각했지만,은, 보간 된 시간 배열 크기를 변경 : 이것은 내 원래의 코드 그래서이 for 루프는 행렬 밖에서 액세스하게합니다. 어떻게 해결할 수 있을지 모르겠습니다.

for i = 1:length(interptimes) 
    for j = 1:length(uniqday) 
     if interptimes(j,1:3) == uniqday(j,:) 
     else 
      interptimes(j,:) = []; 
     end 
    end 
end 

답변

0

당신은 uniqday에있는 일을 찾기 위해 ismember을 사용할 수

newtimesvec2 = newtimesvec(ismember(newtimesvec(:,1:3),uniqday,'rows'),:);