struct - getting field name as a string in matlab -


i have matlab reference manual

value = getfield(struct, 'field')

where struct 1-by-1 structure, returns contents of specified field, equivalent

value = struct.field

how can opposite

getstringname(struct.field) return 'field'

also if possible point @ field in numerical way similar array

like struct{1} field 1 field

edit

if follow

structname(1) list of field names, , dimentions

                speed: [2244x1 double]                  time: [2244x1 double] ... , on  

i want grab title speed string, , if possible

structname(1).filed(1) speed without doing structname(1).speed

i want print each field file field name!

so if do

for i=1:sizeofstruct    printtofile(structname(i)); %<=== accessing field index, problem 2 end  function printtofile(structfield)    structfieldstr = getstrfiledname(structfield); %<=== obtain field string, main problem    filename = strcat(fileloc, '/profile/', structfieldstr, '.dat');    %...   open file , dump end 

not complete answer question, should started:

s.a = 11; s.b = 22; s.c = 33; names = fieldnames(s); = 1:length(names)     fprintf('field %s = %g\n', names{i}, s.(names{i})) end 

result:

field = 11 field b = 22 field c = 33 

note syntax programmatically access field name: s.(name), s struct , name string.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -