Call the most recent timetable value

조회 수: 3 (최근 30일)
Poison Idea fan
Poison Idea fan 2021년 3월 3일
답변: Poison Idea fan 2021년 3월 3일
I have 2 timetables. In order to make a calculation on the data in the first table, I need to call the most recent values of the second table.
for k = 1:numel(rawData_Timetable)
value(n,:) = reflectivity_Timetable.('Reflectivity')(most_recent) .* rawDataTT.('Spectra')(n,:);
end
How could I compare the times in the rawData_Timetable and find the most recent row of the reflectivity_Timetable for the calculation?
Initially I thought to loop through the reflectivity_Timetable and concatenate to a new timetable, but I feel there must be asolution that doesn't involve creating a nested loop through the rawData_Timetable and reflectivity_Timetable.

채택된 답변

Poison Idea fan
Poison Idea fan 2021년 3월 3일
So, I answered my own question. But, maybe someone has a better solution!
I take the difference between the times of the measurements and remove all of the positive durations. I do this because you will always need the previous reflectivity measurement. Then i find the minimum of the absolute value of the duration and save the index in a new array.
x = refTT.('Time'); % this is unnecessary but I initialize arrays with the datetimes
y = [rawDataTT.('Var1')];
for n = 1:height(refTT) % take the time diff for each rawDataTT row
time_diff(n,:) = x(n,1)-y(:,1);
end
time_diff(time_diff > 0) = NaN; % remove positive durations
[~,I] = min(abs(time_diff(:,:)),[],'omitnan'); % find the minimum backwards duration
for k = 1:height(rawDataTT) % do the calculation with the index in I
extinction(k,:) = refTT.('Reflectivity')(I(k),:) + ext_bath .*...
(rawDataTT.('Spectra')(k,:);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by