Reputation: 904
I load couple audio files from a folder with the audioread function as following:
for audio_numm = 1:24
[sound{audio_numm},freq{audio_numm} ] = audioread(strcat('./M_S',int2str(audio_numm),'.wav'));
end
It loads without any problem, but when i try to play any of them with the following function:
for i=1:24
sound(sound{i})
end
I get the following error:
Subscript indices must either be real positive integers or logicals.
.wav file is saved in an 1x24 array where each element is another one dimensional array. How can I fix this problem?
Upvotes: 2
Views: 116
Reputation: 1550
The error comes from the fact that a variable is named with a build in function name sound
.
What Matlab says is:
Avoid creating variables with the same name as a function (such as i, j, mode, char, size, and path). In general, variable names take precedence over function names. If you create a variable that uses the name of a function, you sometimes get unexpected results.
So in the for loop, what you expected to be the function is actually the variable sound
. So it was indexed with non integer values.
You can check if a name is already taken with the command exists
, it will return zero if the name is not taken:
exist toto
ans =
0
Thanks @Brice for correcting me.
Upvotes: 2