MATLAB: Save struct indexed name as a variable

MATLABstruct

This may sound Weird, Yet I need to save a struct index string as a variable. reason:The struct is formed as a query request for stock values – and in order to draw a valid graph the date is needed – the Date is the name of the struct Struct:
% code

end
stock.TimeSeries_Daily_
% Within
stock.TimeSeries_Daily_
% the struct continues as:
stock.TimeSeries_Daily_.x2017_12_01,
stock.TimeSeries_Daily_.x2017_11_30,
stock.TimeSeries_Daily_.x2017_11_29,
stock.TimeSeries_Daily_.x2017_11_28,
stock.TimeSeries_Daily_.x2017_11_27
and so on
Within final struct I get the needed value
Yet I need a variable to hold:
if true
% code
end
2017_11_30
2017_11_29
2017_11_28
and so on..
meaning I need to save the "name" of the struct into a different varible
How do I do this??
Thank you in Advance

Best Answer

You can use FIELDNAMES:
FN = fieldnames(stock.TimeSeries_Daily_)
% process these names in more common date formats using datenum and datestr
num = datenum(FN,'xyyyy_mm_dd')
str = datestr(num,'yyyymmdd')