Looping interpolation scheme has errors for some (but not all) datasets?
이전 댓글 표시
Hello,
I'm having trouble with an interpolation function I'm trying to write, for use with multiple large datasets. For each dataset, I will have a given time period and two time series: 'a', with data taken at 64-second intervals, and 'b', with data taken at 60-second intervals. I want to resample the 'a' dataset to have the same length as the 'b' dataset, using this code:
resampled_a_data = 1:1:length(b_data);
a_timestamps = 0:64:(64*length(a_data));
timestamp = 0;
for i = resampled_a_data
%find index j of closest value in a_timestamps
j = interp1(a_timestamps,1:length(a_timestamps),timestamp,'nearest');
a_datapoint = a_data(j);
%replace resampled_a_data[i] with a_data[j]
resampled_a_data(i) = a_datapoint;
timestamp = timestamp + 60;
end
I have tried this code with three datasets so far. One of them works perfectly well, but for the other two datasets, the scheme gives an error at
a_datapoint = a_data(j);
when i is somewhere in the 40000s (it is different for both datasets), and for all i after that datapoint. Prior to giving an error, the contents of the array resampled_a_data are exactly what I would expect them to be. Can anyone advise me on how to fix this error, or alternatively, a better way to accomplish the same goal of resampling the datasets?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Interpolation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
