use sprintf with .wav files in for-loop
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
harrie houthakker
am 10 Mai 2018
Kommentiert: Jan
am 10 Mai 2018
Hi,
How do i properly recall a .wav file in a for-loop? Changing the name of the variable with sprintf gives me an error.
[wav1,Fs] = audioread('wav1.wav');
[wav2,Fs] = audioread('wav2.wav');
[wav3,Fs] = audioread('wav3.wav');
n = 3;
for k = 1:n
wavx = sprintf('wav%d', k);
[acor,lag] = xcorr(wav1,wavx);
end
I hope someone can help me, thanks a lot in advance!
3 Kommentare
Von Duesenberg
am 10 Mai 2018
Bearbeitet: Von Duesenberg
am 10 Mai 2018
In this case you may want to store the your signals in a cell array and then loop through your cell array. And xcorr does the padding for you.
Akzeptierte Antwort
Von Duesenberg
am 10 Mai 2018
Bearbeitet: Von Duesenberg
am 10 Mai 2018
Or, assuming this is for the same piece of homework as yesterday, this can help you (although I hesitate to suggest it as an answer as it does not answer your question):
myFiles = uigetfile('*.wav', 'MultiSelect', 'on');
mySignals = cell(length(myFiles),1);
for iFile = 1:length(myFiles)
mySignals{iFile} = audioread(char(myFiles(iFile)));
end
Weitere Antworten (1)
Walter Roberson
am 10 Mai 2018
2 Kommentare
Jan
am 10 Mai 2018
@harrie: The application of xcorr is not a problem in any way, if you use a cell array. wav{1} is much better than wav1, because you can access it easily in a loop.
Siehe auch
Kategorien
Mehr zu Array and Matrix Mathematics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!