Extracting data from timetable
38 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Thomas Lees
le 28 Juin 2022
Réponse apportée : Star Strider
le 28 Juin 2022
I have a timetable with multiple variables which vary spatially and temporally and spatially across a transect.
The variables are recorded at millimeter and minutely intervals. These are shown below as 'V_1, V_2, V_3, V_4, V_5... V_300'. The number here refers to the millimeter at which the measurements were taken, at time steps of t1, t2, t3... tn.
One variable ('Event') occurs at discrete time points and at discrete locations along the transect. Event data is either not present (NaN), or present (recorded as a number). For the 'present' events, the number refers to the spatial dimension: the millimeter along the transect at which tte event occurred.
The picture below shows a simplified view of the data, with annotations showing what I'd like to do.
I would like to:
- Output the value of the environmental variable at the time of each 'Event'.
- Calculate and output the change in each environmental variable for the preceding n timesteps that lead up to each 'Event'.
Is this possible, and how would I got about it?
Thank you very much.
0 commentaires
Réponse acceptée
Star Strider
le 28 Juin 2022
I am not certain what you want.
This should get you started —
tv = minutes(0:15).'; % Create Data, Table & Timetable
V = sort(rand(numel(tv), 4)*100);
Event = NaN(size(tv));
Event(6:5:end) = 1:3;
T1 = table(tv,V(:,1),V(:,2),V(:,3),V(:,4),Event, 'VariableNames',{'Time(min)','V1','V2','V3','V4','Event'});
TT1 = table2timetable(T1)
EvIdx = find(~ismissing(TT1.Event)); % Event Index Vector
TTs = TT1(EvIdx(1):EvIdx(2)-1,1:end-1) % First Section
td(1) = TTs.('Time(min)')(end) - TTs.('Time(min)')(1);
Vd(1,:) = TTs{end,:} - TTs{1,:};
for k = 1:numel(EvIdx)-1
TTs = TT1(EvIdx(k):EvIdx(k+1)-1,1:end-1) % Intermediate Sections
td(k+1) = TTs.('Time(min)')(end) - TTs.('Time(min)')(1);
Vd(k+1,:) = TTs{end,:} - TTs{1,:};
end
Out = array2table([minutes(td(:)), Vd], 'VariableNames',{'TimeSpan(min)',TT1.Properties.VariableNames{1:4}})
It takes the differences between the beginning and end values of each secton and saves them to ‘td’ and ‘Vd’ then puts those results in a table.
.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!