#matlab #path #directory
#matlab #путь #каталог
Вопрос:
В моем коде я хочу, чтобы пользователь вручную выбирал папку с файлами .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
функцию?
Для перебора я нашел ответ stackexchange, который охватывал это.
files = dir('C:myfolder*.txt');
for k = 1:length(files)
load(files(k).name, '-ascii')
end
Комментарии:
1. Используйте синтаксис функции вместо синтаксиса команды, т. Е.
cd( dname )
. Или, что еще лучше, не меняйте каталог и загружайте полный путь, т.Е.load( fullfile( dname, files(k).name ) )
?2. cd (dname) сработал!
Ответ №1:
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