get the columne name from a structure in matlab

To get the field names (i.e., column names) of a structure in MATLAB, you can use the fields function. Here's an example:

main.m
myStruct.foo = 1:5;
myStruct.bar = 'hello';
myStruct.baz = magic(3);

fieldNames = fields(myStruct);
disp(fieldNames);
119 chars
7 lines

This will output:

main.m
'foo'    'bar'    'baz'
24 chars
2 lines

So the fields function returns a cell array of strings, where each string is the name of a field (i.e., column name) in the structure.

related categories

gistlibby LogSnag