How to restart the time for each trial? (help with a for loop in a table)
조회 수: 2 (최근 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!