I have this from the matlab reference manual
value = getfield(struct, 'field')
where struct is a 1-by-1 structure, returns the contents of the specified field, equivalent to
value = struct.field
how can I do the opposite
getStringName(struct.field) which return 'field'
also if it is possible to point at the field in numerical way similar to an array
like struct{1} for field 1 field
edit
if I do the follow
structName(1) I get a list of field names, and dimentions
Speed: [2244x1 double] Time: [2244x1 double] ... and so on I want to grab the title speed as string, and if possible
structName(1).filed(1) for Speed without doing structName(1).Speed
I want to print each field into a file with the field name!
so if I do
for i=1:sizeOfStruct printToFile(structName(i)); %<=== accessing field by index, problem 2 end function printToFile(structField) structFieldStr = getStrFiledName(structField); %<=== obtain field string, main problem filename = strcat(fileLoc, '/profile/', structFieldStr, '.dat'); %... then open file and dump everything end
struct.fieldis just a value, for example2.5, and no longer has any ties to the struct object.fieldnamesfunction give what you want, or are you trying to find the field which contains a certain value? You can also tryinputname, not sure if that works with structure members