Call the most recent timetable value

3 次查看(过去 30 天)
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