How to show part of a nested structure as a vector?
Afficher commentaires plus anciens
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?
Réponses (2)
Vladimir Sovkov
le 18 Déc 2019
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
le 18 Déc 2019
seine_1_data = cellfun(@str2num, struct2cell(all_seines.seine_1));
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!