필터 지우기
필터 지우기

Extracting values data from variable field to a matrix

조회 수: 2 (최근 30일)
maxence rateaux
maxence rateaux 2018년 4월 18일
댓글: maxence rateaux 2018년 4월 19일
I want to extract in a matrix all the datas of the field Latency. I passed to extract the first value with the code
trials_struct{1,1}.Latency
But I don't find the solution to get all value in one matrix in one loop.

채택된 답변

Stephen23
Stephen23 2018년 4월 18일
편집: Stephen23 2018년 4월 18일

Your misleadingly named trials_struct is actually a 1x186 cell array, each cell contains one scalar structure with multiple fields. Unfortunately the fieldnames are not all the same: if they were then your data would be better stored in a non-scalar structure, then the solution to your task is also trivial:

[real_struct.Latency]

Unfortunately because the fieldnames differ you will have to stick with a cell array and use a loop or cellfun:

cellfun(@(s)s.Latency,trials_struct)

In this case it worked, but note that if any of the scalar structures does not have that field Latency, then the code will throw an error.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by