%% Specify Iteration Dimension
% You can select the dimension in which to read from an ArrayDatastore. For example, you can read the frames of a video whose data is stored in an ArrayDatastore by reading along the fourth dimension.
% Load the video data. Create a VideoReader object from the file xylophone.mp4.

v = VideoReader('xylophone.mp4');

% Read all video frames from the VideoReader object into the workspace.

allFrames = read(v);

% Create a datastore from the frames you read. Set 'IterationDimension' to 4 to read the data along its fourth dimension. Set 'OutputType' to 'cell' to return the data as a cell array. Set 'ReadSize' to 4 to read four video frames in each call to the read function.

arrds = arrayDatastore(allFrames,"IterationDimension",4,"OutputType","cell","ReadSize",4)

% Read and display the first four video frames in the datastore as a rectangular tiled image.

frames = read(arrds);
imout = imtile(frames);
imshow(imout)

% Copyright 2020 The MathWorks, Inc.
%