database - Access a particular field in a structure within a Matlab structure -
this question has answer here:
i need access structure inside structure: have main structure called globalstruc has many items (my "packets"). each packets contains many info, i.e. has many fields. 1 of structure several fields. need have access each of these fields. idea?
to sum up: globalstruc.detailsstruc contains many fields , has many indexes. how can have access these? if more convinient, can create array these fields? characteristicofthepacket = globalstruc(index).detailsstruc.fieldthatiwant
here example of how main structure built: `
globalstruc(1).data1 = 1; globalstruc(1).data2 = 12; globalstruc(1).moredata.velocity = 327; globalstruc(1).moredata.bbeta = 3.2; globalstruc(2).data1 = 23; globalstruc(2).data2 = 56; globalstruc(2).moredata.velocity = 442; globalstruc(2).moredata.bbeta = 1.7; globalstruc(3).data1 = 4.3; globalstruc(3).data2 = 7; globalstruc(3).moredata.velocity = 556; globalstruc(3).moredata.bbeta = 1.1;
` wish say:
myvelocities=globalstruc(:).moredata.velocity;
but error :
expected 1 output curly brace or dot indexing expression, there 3 results.
thank much,
you cannot in single line, can do:
innerstruct = [globalstruc.moredata];
then access first element:
innerstruct(1) ans = velocity: 327 bbeta: 3.2000
or ith element of structure:
innerstruct(i)
Comments
Post a Comment