Know the number of row within a structure (struct)

조회 수: 19 (최근 30일)
Alberto Acri
Alberto Acri . 2022년 11월 10일
댓글: Alberto Acri . 2022년 11월 10일
Hi! I have the following 'CODE' struct.
I would like to know if there is a code to determine the row number (present in 'Fields', for example 7) considering this as input:
folder = 'C:\Users\Alberto\Desktop\GLOBAL\DATA 4'
Thanks!
  댓글 수: 2
Alberto Acri
Alberto Acri 2022년 11월 10일
편집: Alberto Acri 님. 2022년 11월 10일
@Stephen23 Yes, I know! I wanted to determine element 7 of struct CODE in correspondence of 'name' 'a'.
But the same is true for example at element 1,4,10 of struct CODE at 'name' 'a' where 'DATE 1', 'DATE 11' and 'DATE 6' are given respectively.

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

채택된 답변

Joseph Cheng
Joseph Cheng 2022년 11월 10일
so you can use the function find() and contains(). in this example i am just searching the name entry but it should work with your folder instead.
abc = 'a'-1;
for ind = 1:10
CODE(ind).name = char(abc+ind);
end
foundRow = find(contains({CODE.name},'d'))
foundRow = 4
Where by doing {CODE.name} here it'll make each entry into a cell then find which one contains your desired text.
  댓글 수: 4
Alberto Acri
Alberto Acri 2022년 11월 10일
perfect @Stephen23!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by