struct - Select where type command for Matlab structure -
i have 2x3 matlab structure containing following fields:
projectname
, projectcategory
, projectcost
.
here loop goes through contents of structure:
>> i=1:3 projectstructure(i).projectname projectstructure(i).projectcategory projectstructure(i).projectcost end ans = project1 ans = category1 ans = 50000 ans = project2 ans = category2 ans = 25000 ans = project3 ans = category1 ans = 65000 >>
i see if, in matlab, there efficient way "query" structure based on projectname
field. i.e. whether there programmatic way extract projectcategory
field value for, say, projectname3
.
this similar excel vlookup
function or mysql select where
type thing. see if matlab can without having resort large (and costly) database extensions database toolbox.
projectstructure(strcmp({projectstructure.projectname}, 'project3')).projectcategory
explanation
{projectstructure.projectname}
: create cell array of project namesstrcmp({projectstructure.projectname}, 'project3')
: compares names desired oneprojectstructure(strcmp({projectstructure.projectname}, 'project3'))
: select desired project using logical indexing
Comments
Post a Comment