Your OP is failing because of how MATLAB character arrays are implemented (@patrik has a very good explanation in this recent question). If you want to use a character array every row must be the same length, requiring you to pad the entries somehow which, while doable, isn't very efficient. The alternative is to use cell arrays, as @nkjt suggested, which will work for the implementation outlined in your OP.
A more general approach, however, is to use the data structure returned by MATLAB's dir
command to identify all of the *.wav
files in a directory and perform some operation on all of them.
pathname = 'C:\somewavfiles'; % Full path to a folder containing some wav files
wavfiles = dir(fullfile(pathname, '*.wav')); % Obtain a list of *.wav files
% Loop over all the files and perform some operations
for ii = 1:length(wavfiles)
filepath = fullfile(pathname, wavfiles(ii).name); % Generate the full path to the file using the filename and the pathname specified earlier
[y, fs] = wavread(filepath);
a = miraudio(filepath);
z = mirzerocross(a);
end
I have used fullfile
in a few places rather than concatenating strings with a slash in order to avoid compatibility issues between operating systems. Some use \
and others use /
.
Also note that, as explained by the documentation, you can use wildcards (*
) in dir
calls to narrow down the list of files returned.
str=['1.wav';'2.wav';'3.wav';'4.wav';'5.wav'];
? The semicolon is the vertical concatenation operator; no need to use it at the end. - A. Dondastr(i)
will give you a single char, not the full file name. Put it in a cell array instead and usestr{i}
. - nkjt.name
field of the items in the structure returned bydir
withfullfile
in yourwavread
call - excaza