How to use structure variable names in for loop
조회 수: 7 (최근 30일)
이전 댓글 표시
Hello,
I have a .mat file from a source containg structures with variable names as A,B,C etc.
I'm loading those to my workspace,creating a array for variable names and want to access the structures in a for loop. Error Dot indexing is not supported for variables of this type.
----------------------------------------------------------------------------
Structure names={'A','B','C'}
for i=1:3
output= Structure names(i).fieldname
end
댓글 수: 5
채택된 답변
Tommy
2020년 4월 28일
Loop through the structures instead of their names:
Structure={A,B,C,..,n};
for i=1:numel(Structure)
output= Structure{i}.fieldname;
end
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!