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

3 ビュー (過去 30 日間)
Samantha Tomkowich
Samantha Tomkowich 2019 年 12 月 18 日
回答済み: Bhaskar R 2019 年 12 月 18 日
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 Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by