How to show part of a nested structure as a vector?
조회 수: 2 (최근 30일)
이전 댓글 표시
I created a nested structureband I am trying to find the abundance of all species in seine 1 as a vector. I know how to access the information
seine1=struct('atlantic_menhaden','502','atlantic_silverside','15','bay_anchovy','0','silver_perch','13','summer_flounder','1');
seine2=struct('atlantic_menhaden','2800','atlantic_silverside','38','bay_anchovy','2','silver_perch','5','summer_flounder','0');
seine3=struct('atlantic_menhaden','3','atlantic_silverside','0','bay_anchovy','1','silver_perch','2','summer_flounder','1');
all_seines=struct('seine_1',seine1,'seine_2',seine2,'seine_3',seine3)
all_seines.seine_1 %data I want to use
however it needs to be in a vector format. How do i display it as such?
댓글 수: 0
답변 (2개)
Vladimir Sovkov
2019년 12월 18일
sn='seine_1';
% sn=fieldnames(all_seines);
% sn=sn{1};
nm=fieldnames(all_seines.(sn));
N=numel(nm);
A=zeros(N,1);
for k=1:N
A(k)=str2double(all_seines.(sn).(nm{k}));
end
disp('-----');
disp(A);
댓글 수: 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!