필터 지우기
필터 지우기

how to know first element in Data struct

조회 수: 7 (최근 30일)
aldo
aldo 2023년 11월 29일
댓글: Stephen23 2023년 11월 29일
i want the first element of all field in struct
>> whos Sis
Name Size Bytes Class Attributes
Sis 1x351 120517682 struct
Sis(1).data(1)
ans =
datetime
2008-01-01
but i want to know Sis(1).data(1) for all element in struct(351 element)
i can't to use
data=[Sis.data];
Error using datetime/horzcat
Dimensions of arrays being concatenated are not consistent.

채택된 답변

Stephen23
Stephen23 2023년 11월 29일
arrayfun(@(s)s.data(1),Sis)
  댓글 수: 1
Stephen23
Stephen23 2023년 11월 29일
Lets try it:
S = struct('data',{datetime(2023,11,1:5),datetime(2023,1,1:4)},'other',{eps,pi})
S = 1×2 struct array with fields:
data other
arrayfun(@(s)s.data(1),S)
ans = 1×2 datetime array
01-Nov-2023 01-Jan-2023

댓글을 달려면 로그인하십시오.

추가 답변 (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