MATLAB Answers

Issue loading audio files from "fileDatastore" to a matrix

4 views (last 30 days)
Ibrahim A
Ibrahim A on 2 Nov 2019
Commented: Ibrahim A on 4 Nov 2019
I have used fileDatastore to link my 3K audio files from three different floders, then I tried to input their values into three different matrix so I can start extracting features from these audio files. When the Matlab starts to load the audio files into the matrix, it stops loading after a certain number of files, and it is different from folder to folder. For example, in group A folder it will stop after loading 585 files and show this error "Unable to perform assignment because the indices on the left side are not compatible with the size of the right side." Group B it stoped after loading 287.
All of the audio files in this dataset are .wav and for 5 sec long with 128kbps Bit rate
Please help me with this problem or if you have any other way to do this.
Gro_A_fds = fileDatastore(fullfile(pwd, 'Data', 'A/'), 'ReadFcn', @audioread, 'FileExtensions','.wav');
Gro_B_fds = fileDatastore(fullfile(pwd, 'Data', 'B/'), 'ReadFcn', @audioread, 'FileExtensions','.wav');
Gro_C_fds = fileDatastore(fullfile(pwd, 'Data', 'C/'), 'ReadFcn', @audioread, 'FileExtensions','.wav');
A_Count = cell(1,numel(Gro_A_fds.Files));
B_Count = cell(1,numel(Gro_B_fds.Files));
C_Count = cell(1,numel(Gro_C_fds.Files));
A_Count = numel(A_Count) % to make sure it loaded all of 1000 files
B_Count = numel(B_Count)
C_Count = numel(C_Count)
%% The output %%
A_Count = 1000
A_Count = 1000
A_Count = 1000
k=1;
reset(Gro_A_fds);
while hasdata(Gro_A_fds) && k <=1000 % I sure the k statment to stop and move to the next one before it reachs the error.
A_data(:,k)= read(Gro_A_fds);
fprintf('file %d from A was loaded.\n',k);
k= k+1;
end
%% The output %%
file 1 from A was loaded.
....
....
file 585 from A was loaded.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
k=1;
reset(Gro_B_fds);
while hasdata(Gro_B_fds) && k <=1000 % I sure the k statment to stop and move to the next one before it reach the error.
B_data(:,k)= read(Gro_B_fds);
fprintf('file %d from B was loaded.\n',k);
k= k+1;
end
%% The output %%
file 1 from B was loaded.
....
....
file 286 from B was loaded.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
k=1;
reset(Gro_C_fds);
while hasdata(Gro_C_fds) && k <=1000 % I sure the k statment to stop and move to the next one before it reach the error.
C_data(:,k)= read(Gro_C_fds);
fprintf('file %d from C was loaded.\n',k);
k= k+1;
end
%% The output %%
file 1 from C was loaded.
....
....
file 994 from C was loaded.
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
workspace.PNG

  0 Comments

Sign in to comment.

Accepted Answer

jibrahim
jibrahim on 4 Nov 2019
you need to solve both issues 1) and 2) highighted in my first response.
I suspect you need to fix this line:
C_data(:,k)= read(Gro_C_fds);
Make sure C_data's first dimension is large enough to accomodate the longest signal in the dataset. Then you can do something like:
x = read(Gro_C_fds);
C_data(1:length(x),k)= x;

More Answers (1)

jibrahim
jibrahim on 4 Nov 2019
Hi Ibrahim,
1) It looks like you are writing the return output of reasd into a matrix. It might be that some of the audio files have signals that are not exactly 40001 samples long.
2) I recommend you use audioDatastore instead of fileDatastore. audioDatastore was specifically designed to manage datasets of audio files

  1 Comment

Ibrahim A
Ibrahim A on 4 Nov 2019
Hi jibrahim,
Thank you for answering my question. I agree with you that the problem is with my audio files. However, I tried your suggestion but I still have the same issue. Any other suggestions?
I'm attaching a screenshot.
Best,
Ibrahim Ans.PNG

Sign in to comment.

Sign in to answer this question.


Translated by