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 names
  • strcmp({projectstructure.projectname}, 'project3'): compares names desired one
  • projectstructure(strcmp({projectstructure.projectname}, 'project3')): select desired project using logical indexing

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -