Программно открывать папку и загружать и обрабатывать файлы по заданному пути - PullRequest
0 голосов
/ 11 апреля 2019

В моем коде я хочу, чтобы пользователь вручную выбирал папку с файлами .wav для обработки.

Я использовал:

dname=uigetdir('C:'); 

%% dname gives the path to the folder directory and saves it as a variable

Я знаю, что вы можете использовать cd directory name и cd .., как в Linux с MATLAB, как мне отсоединить значимую часть dname, чтобы можно было использовать функцию cd?

Для прохождения цикла я нашел ответ на обмен стека, который охватывал это.

files = dir('C:\myfolder\*.txt');
for k = 1:length(files)
    load(files(k).name, '-ascii')
end

1 Ответ

0 голосов
/ 12 апреля 2019
dname=uigetdir('C:'); 

cd(dname); %make current directory, the directory specified by the path

files=dir('*.wav'); %get all the .wav files in the folder
for k=1:length(files); % loop through the files 1:last.wav 

    audio=cell(1, length(files)); %preallocate a cell with the appropriate size
    audio{k} = audioread(files(k).name); %input in the files

end   %files struct can be called after the end

output

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...