How to show part of a nested structure as a vector?

3 次查看(过去 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?

回答(2 个)

Vladimir Sovkov
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);

Bhaskar R
Bhaskar R 2019-12-18
seine_1_data = cellfun(@str2num, struct2cell(all_seines.seine_1));

类别

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