use sprintf with .wav files in for-loop

1 回表示 (過去 30 日間)
harrie houthakker
harrie houthakker 2018 年 5 月 10 日
コメント済み: Jan 2018 年 5 月 10 日
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 件のコメント
harrie houthakker
harrie houthakker 2018 年 5 月 10 日
allright, unfortunately they do not have the same amount of samples. But if so, (maybe with zeropadding), would that be any useful when my goal is to align them with xcorr? thanks
Von Duesenberg
Von Duesenberg 2018 年 5 月 10 日
編集済み: Von Duesenberg 2018 年 5 月 10 日
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.

サインインしてコメントする。

採用された回答

Von Duesenberg
Von Duesenberg 2018 年 5 月 10 日
編集済み: Von Duesenberg 2018 年 5 月 10 日
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
  1 件のコメント
harrie houthakker
harrie houthakker 2018 年 5 月 10 日
Thank you so much.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 5 月 10 日
  2 件のコメント
harrie houthakker
harrie houthakker 2018 年 5 月 10 日
i came across this earlier indeed, but i find it difficult to find a better solution for my problem. Because my goal is to align the .wav files with xcorr.
Jan
Jan 2018 年 5 月 10 日
@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.

サインインしてコメントする。

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by