MATLAB: How to obtain audio and video characteristics in multimedia info when I’m using a for loop

index exceeds matrix dimensions video audioMATLABMATLAB and Simulink Student Suite

I'm using this code but the multimedia characteristics from avi files are not showed and Matlab send me this error after run the program: ??? ??? Index exceeds matrix dimensions What I want is to obtain characteristics from audio and video from this files but I need a loop because there are too many files
files= dir('*.avi');
numfiles=length(files);
mydata= cell(numfiles,1);
info=cell(numfiles,1);
for j=1:numfiles
info{j}=mmfileinfo(files(j).name);
audio=info(j).Audio
video=info(j).Video
end
for k=1:numfiles
mydata{k}=importdata(files(k).name);
end

Best Answer

The code below should fix the issue:
files= dir('*.avi');
numfiles=length(files);
mydata= cell(numfiles,1);
info=cell(numfiles,1);
isFileSupported = true(numfiles, 1) ;
for j=1:numfiles
try
info{j}=mmfileinfo(files(j).name);
audio = info{j}.Audio
video = info{j}.Video
catch ME
isFileSupported(j) = false;
continue;
end
end
supportedFiles = files(isFileSupported);
for k=1:numel(supportedFiles)
mydata{k}=importdata(supportedFiles(k).name);
end
Hope this helps.
I would not recommend importing the data of all files into MATLAB at once because this can eat up a lot of memory depending upon the file size. Import data for each file as you need it.
Hope this helps.
Dinesh