Assigning Columns to a table without using loops - and perform i.e. diff on a column
7 ビュー (過去 30 日間)
古いコメントを表示
Hello, I have an events log that I want to be able to pull out relevant times and types of triggers into an array of some sort. As its a mixture of text and numbers I originally thought of using a cell array, but have since preferred the idea of using a table.
Ultimately I want a table showing
[count, FrameNumber, (AbsTime-AbsTime_from_1st event) trigger type
All of this info is available in the events.Data and events.type fields
This was my basic attempt to get going
Type=events(:).Type
AbsTime=datetime(events(:).Data.AbsTime)
T0=datetime(events(1).Data.AbsTime)
D=diff(T0)
table(Type,AbsTime,T0,D)
But I see an error
Intermediate dot '.' indexing produced a comma-separated list with 5 values, but it must produce a single value when followed by subsequent indexing
operations.
Error in HTS_TestSoftware/StopVidButtonPushed (line 8572)
AbsTime=datetime(events(:).Data.AbsTime)
Does this mean I have to use loops then?
Also how do I include the diff of the abs time to get each individual time difference?
events =
1×5 struct array with fields:
Type
Data
ans =
struct with fields:
% Here is events.Data-----------------------------------------------
AbsTime: [2025 2 14 15 22 54.8366]
FrameNumber: 0
RelativeFrame: 0
TriggerIndex: 0
ans =
struct with fields:
AbsTime: [2025 2 14 15 22 55.0519]
FrameNumber: 0
RelativeFrame: 0
TriggerIndex: 0
ans =
struct with fields:
AbsTime: [2025 2 14 15 22 55.1534]
FrameNumber: 1
RelativeFrame: 0
TriggerIndex: 1
ans =
struct with fields:
AbsTime: [2025 2 14 15 22 55.2520]
FrameNumber: 2
RelativeFrame: 0
TriggerIndex: 2
ans =
struct with fields:
AbsTime: [2025 2 14 15 22 55.4438]
FrameNumber: 3
RelativeFrame: 1
TriggerIndex: 3
% Here is events.Type-----------------------------------------------
ans =
'Start'
ans =
'Trigger'
ans =
'Trigger'
ans =
'Trigger'
ans =
'Stop'
Type =
'Start'
2 件のコメント
Cris LaPierre
2025 年 2 月 14 日
Please attach your data file and the code you are using to import it.
It is hard to provide a solution specific to your use case without having your data.
採用された回答
Voss
2025 年 2 月 14 日
A struct array similar to your variable events:
tmp = num2cell([2025 2 14 15 22 54.8366; 2025 2 14 15 22 55.0519; 2025 2 14 15 22 55.1534; 2025 2 14 15 22 55.2520; 2025 2 14 15 22 55.4438],2).';
events = struct( ...
'Type',{'Start','Trigger','Trigger','Trigger','Stop'}, ...
'Data',num2cell(struct('AbsTime',tmp,'FrameNumber',{0,0,1,2,3},'RelativeFrame',{0,0,0,0,1},'TriggerIndex',{0,0,1,2,3})))
events(1), events(1).Data
events(end), events(end).Data
One way to build something like the table you're trying to build:
Type = {events.Type}.'
Data = [events.Data]
AbsTime = datetime(vertcat(Data.AbsTime))
% T0 = datetime(events(1).Data.AbsTime)
T0 = AbsTime(1) % same
DT = AbsTime-T0
DT.Format = 'mm:ss.SSSS'
count = (1:numel(events)).';
FrameNumber = vertcat(Data.FrameNumber);
T = table(count,FrameNumber,DT,Type)
10 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
