我想从某个目录中读取几个文件。这是我的剧本:
prefix = '\wav\';
wav_arr = ['1.wav'; '2.wav'; '3.wav'];
wav_arr = cellstr(wav_arr);
len = length(wav_arr);
sig = [];
fs = [];
for i = 1:len
path = strcat(pwd, prefix, wav_arr(i));
[s, curr_fs] = audioread(path);
sig = [sig s];
fs = [fs curr_fs];
end
但我收到错误:
Error using which
Argument must contain a string.
Error in audiovideo.internal.absolutePathForReading (line 7)
whichFileName = which(filename);
Error in audioread (line 74)
filename = audiovideo.internal.absolutePathForReading(...
Error in main_experiment (line 14)
[s, curr_fs] = audioread(path);
问题是path
是1x1 cell
,它不是string
。对cellstr()
执行path
不起作用。
答案 0 :(得分:2)
for i = 1:len
path = strcat(pwd, prefix, wav_arr(i));
[s, curr_fs] = audioread(path);
sig = [sig s];
fs = [fs curr_fs];
end
成为
for i = 1:len
path = strcat(pwd, prefix, wav_arr{i});
[s, curr_fs] = audioread(path);
sig = [sig s];
fs = [fs curr_fs];
end
全部,阅读matlab中有关细胞的文档,以了解细胞(1)和细胞{1}之间的差异