fileDatastore read: Index exceeds the number of array elements (0).
1 view (last 30 days)
Show older comments
Christine Deer
on 1 Jul 2021
Commented: Christine Deer
on 2 Jul 2021
I am attempting to set up a fileDatastore (vds, for video datastore) that will send 1 video file at a time to a modified version of the MotionBasedMultiObjectTrackingExamples.m. I have the following code:
loc = "C:\Users\Christine Deer\Downloads\02242021-SV\02242021-SV";
vds = fileDatastore(loc, 'ReadFcn', @videoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')
data=read(vds);
function v = videoReader(file)
v = videoReader(file);
end
Which generates the following output:
vds =
FileDatastore with properties:
Files: {
' ...\Camera 1 - 192.168.0.105 (FLIR A400) - 14-20210216-210329.mp4';
' ...\Camera 1 - 192.168.0.105 (FLIR A400) - 14-20210218-012228.mp4';
' ...\Camera 1 - 192.168.0.105 (FLIR A400) - 14-20210218-232125(1).mp4'
... and 1 more
}
Folders: {
'C:\Users\Christine Deer\Downloads\02242021-SV\02242021-SV'
}
UniformRead: 0
ReadMode: 'file'
BlockSize: Inf
PreviewFcn: @videoReader
SupportedOutputFormats: [1×16 string]
ReadFcn: @videoReader
AlternateFileSystemRoots: {}
Error using matlab.io.datastore.FileDatastore/read (line 29)
Index exceeds the number of array elements (0).
Error in DatastoreLoad (line 5)
data=read(vds);
This looks like vds is populated with the correct data. What I am confused by is that the data is in vds, but I cant seem to call the read properly to not get an error. Any help understanding this error and its resolution is greatly appreciated and thoroughly welcome,
Christine D
0 Comments
Accepted Answer
Kojiro Saito
on 2 Jul 2021
videoReader function should be VideoReader.
Also, for avoiding function name conflict, it's better to use another name to custom function than videoReader.
vds = fileDatastore(loc, 'ReadFcn', @myVideoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')
function v = myVideoReader(file)
v = VideoReader(file);
end
Or, simply, you don't need to use custom function in this case.
vds = fileDatastore(loc, 'ReadFcn', @VideoReader, 'IncludeSubfolders', ...
true, 'FileExtensions', '.mp4')
More Answers (0)
See Also
Categories
Find more on Camera Calibration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!