How to show part of a nested structure as a vector?
1 次查看(过去 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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!