How to restart the time for each trial? (help with a for loop in a table)
1 次查看(过去 30 天)
显示 更早的评论
I have a table with two columns, TrialNumber and Minutes that I've attached.
I want each trial to start from 0. I was able to restart the the time for the entire table but not sure how to do it for each trial. Here is what I have so far:
u = unique(tt.TrialNumber);
for k = 1:length(u)
b = find(tt.TrialNumber==u(k));
Mins = (tt{:,2} - tt{1,2});
end
2 个评论
回答(1 个)
Prabhan Purwar
2021-5-5
Hi Mirthand,
tt.TrialTime=cell2mat(rowfun(@(m)m-m(1),tt,'GroupingVariables','TrialNumber', ...
'InputVariables','Minutes','OutputFormat','cell'));
Output
>>head(tt)
8×3 table
TrialNumber Minutes TrialTime
___________ _______ _________
15 2.594 0
15 2.6203 0.026367
15 2.6616 0.067684
15 2.6617 0.067763
15 2.6618 0.067834
15 2.6619 0.067898
15 2.6619 0.067958
15 2.662 0.068016
>> i30=find(tt.TrialNumber==30);
>> tt(i30:i30+7,:)
8×3 table
TrialNumber Minutes TrialTime
___________ _______ _________
30 5.8881 0
30 5.9285 0.040365
30 5.9602 0.072087
30 5.9603 0.072205
30 5.9604 0.072305
30 5.9605 0.072389
30 5.9606 0.072463
30 5.9607 0.072535
Hope it helps!
Thanks
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!