%% Field of Element of Structure Array
% Get the value of a field from an element of a structure array returned by the dir function. dir returns a structure array whose elements each contain information about a file in the specified folder.
% Return information about files in the folder C:\Temp. There are 5 files in the folder.

S = dir('C:\Temp')

%
% To display information about the 5th file, index into S.

S(5)

%
% Return the name of the file described by the 5th element of S using the getfield function. When you use getfield, specify indices in a cell array.

value = getfield(S,{5},'name')

%
% As an alternative, index into the structure array, and then use dot notation to specify a field.

value = S(5).name

% Copyright 2018 The MathWorks, Inc.