Accessing a variant object
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Deepa Maheshvare
am 27 Apr. 2019
Beantwortet: Jeremy Huard
am 29 Apr. 2019
I have a variant object of the following form
ContentIndex: Type: Name: Property: Value:
1 parameter A InitialAmount 5
2 species B InitialAmount 10
3 compartment C InitialAmount 15
How to I access the rows with type species alone?
Thanks a lot
0 Kommentare
Akzeptierte Antwort
Jeremy Huard
am 29 Apr. 2019
Hi Deepa,
you can access the variant content with the dot notation.
If your variant is called v, v.Content will be an array of cell array with one row per component in this variant.
That being said, I like to convert variants into a table to handle it. For this you can use the following function:
function tableObj = sbiovariant2table(variantObj)
% tableObj = sbiovariant2table(variantObj)
%
% Converts the content of a variant to a Table that can be exported to
% Excel with writeTable
content = vertcat(variantObj.Content{:});
tableObj = cell2table(content,'VariableNames',{'Type','Name','Property','Value'});
tableObj.Name = string(tableObj.Name);
tableObj.Type = categorical(tableObj.Type);
tableObj.Property = categorical(tableObj.Property);
tableObj.Properties.Description = variantObj.Name;
end
With this function you can retrieve all species easily:
tableVar = sbiovariant2table(v);
speciesInVar = tableVar(tableVar.Type == 'species',{'Name','Value'})
0 Kommentare
Weitere Antworten (0)
Communitys
Weitere Antworten in SimBiology Community
Siehe auch
Kategorien
Mehr zu Import Data finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!