MATLAB: Accessing field names in struct

MATLABstruct

I've the following struct
test = struct(...
'a',false,...
'b',false,...
'c',false,...
'd',false,...
'e',false,...
'f',false,...
'g',true...
);
How do get the field name that has a value true ?
Expected result:
g
Any suggestions?

Best Answer

F = fieldnames(test) ;
F(cell2mat(struct2cell(test)))