Combining Similar Time Arrays into a Single Updated Time Array
조회 수: 8 (최근 30일)
이전 댓글 표시
I have two structures: Structure A and Structure B.
Both structures have 130 field variables. These variables are time/values on two different DAQs. Structure A uses DAQ A. Structure B uses DAQ B. As such, they have similar but not the same outputs. Sometimes Structure A Field variables have a time/value drop out while Structure B field variables do not.
How do I combine Field Variable 1 from Structure A and Structure B into a single field variable into structure C without any time/value repeats? Then repeat this process for all of the variables.
Assumption: The data values are the same value at the same time even if the indices do not line up. They end at the same time, but are not the same sizes.
Inputs:
StructureA.FieldVariable1.Time
StructureA.FieldVariable1.Value
StructureB.FieldVariable1.Time;
StructureB.FieldVariable1.Value
Output:
StructureC.FieldVariable1.Time
StructureC.FieldVariable1.Value
Ex:
FROM:
Structure A Field Variable 1 Structure B Field Variable 1
Time Data Time Data
1 0.1 2 0.2
2 0.2 3 0.3
4 0.4 5 0.5
5 0.5 6 0.6
6 0.6 7 0.7
8 0.8 8 0.8
10 1.0 9 0.9
Left blank on purpose 10 1.0
Structure C Field Variable 1
Time Data
1 0.1 (Filled in from Structure A)
2 0.2 (same value so filled in from either structure)
3 0.3 (Filled in from Structure B)
4 0.4
5 0.5
6 0.6
7 0.7
8 0.8
9 0.9
10 1.0
댓글 수: 0
답변 (1개)
Star Strider
2025년 4월 24일
There are some core MATTLAB approaches for this, depending on the result you want.
You would have to convert them to timetable arrays, and after that you can use either retime or synchronize depending on the result you want. I am not sufficiently clear on that to suggest a specific apprroach.
Example —
AFV_1 = table(seconds([1;2;4;5;6;8;10]),[1;2;4;5;6;8;10]/10, VariableNames=["Time","Data"]);
BFV_1 = table(seconds([2;3;4;5;6;7;8;9;10]),[2;3;4;5;6;7;8;9;10]/10, VariableNames=["Time","Data"]);
AFV_1TT = table2timetable(AFV_1)
BFV_1TT = table2timetable(BFV_1)
CFV_TT = synchronize(AFV_1TT, BFV_1TT)
CFV_TT2 = table;
CFV_TT2.Time = CFV_TT.Time;
CFV_TT2.Data = mean(CFV_TT{:,[1 2]}, 2, 'omitnan')
Make appropriate changes to get the result you want.
.
댓글 수: 2
Star Strider
2025년 4월 25일
My pleasure!
The datetime function can do microseconds. You have to specify the seconds field as ss.SSSSSS with s denoting seconds and the S denoting fractions of a second.
Example —
T = datetime(2025, 04, 25, 10, 22, 42.123456, Format='dd-MMM-yyyy HH:mm:ss.SSSSSS')
format longG
s = second(T)
Note that the microseconds are preserved, even if they aren't all displayed correctly in the original datetime call.
I'm not sure what other problems you may be having, however datetime is a powerful function and the timetable functions can make your tasks immeasurably easier.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 National Instruments Frame Grabbers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!