Find time elapsed in a table (for loop)?

2 vues (au cours des 30 derniers jours)
Mirthand
Mirthand le 18 Avr 2021
Commenté : Mirthand le 21 Avr 2021
I have a table with two columns, TrialNumber and Minutes (attached).
The trials represented are
15
30
45
60
75
90
Using the Minutes column, how can I find how much time has elapsed for each of the trials?
I think to do this I would want to subtract the last row with the trial and take the Minutes and subtract from the first row with the trial.
Thank you in advance for your help!

Réponse acceptée

Megumi Fukuda
Megumi Fukuda le 18 Avr 2021
Hi Mirthand,
Disclaimer: This anser is based on an assuption that the first row with a tt.TrialNumber contains the time ('tt.Minutes') where the trial actually started.
Your comment "I think to do this I would want to subtract the last row with the trial and take the Minutes and subtract from the first row with the trial." sounds sensible, and here is a snippet. duration_eachtrial should be what you want.
load tt.mat
allTrials = unique(tt.TrialNumber); % extract all the trials in the mat file
for idx_trial = 1:length(allTrials)
tmp_trialidx=find(tt.TrialNumber==allTrials(idx_trial));
duration_eachtrial(idx_trial) = tt.Minutes(tmp_trialidx(end))-tt.Minutes(tmp_trialidx(1));
end
  1 commentaire
Mirthand
Mirthand le 21 Avr 2021
Thank you very much!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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!

Translated by