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 件のコメント
Sargondjani
2021 年 4 月 18 日
It is not clear to me what you want: "I want each trial to start from 0"?
回答 (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!