specify directory and automatic save files in loop

조회 수: 11 (최근 30일)
Mohamed Gamal
Mohamed Gamal 2018년 3월 19일
답변: Mohamed Gamal 2018년 3월 20일
Hello everybody: I have a matrix have composed of several columns sometimes 24 other times 6 etc. I want to choose a folder and then automatic save colums as wav files such as: 1.wav, 2.wav ....24.wav, but this code failed to work ?? Does anybody know how to do it ??
folder = uigetdir(); % Or wherever you want.
for i = 1 : n
% Create a filename.
baseFileName = sprintf('Cell%d.wav', i);
filename = fullfile(folder, baseFileName);
% Write the wav files.
wavwrite(mat(:,i),Fs,16,filename);
end
  댓글 수: 3
Mohamed Gamal
Mohamed Gamal 2018년 3월 19일
I need to know how I can do this please my code does not write the files ??
Akira Agata
Akira Agata 2018년 3월 20일
I would recommend replacing wavwrite with audiowrite, like:
audiowrite(filename,mat(:,i),Fs)

댓글을 달려면 로그인하십시오.

채택된 답변

Mohamed Gamal
Mohamed Gamal 2018년 3월 20일
Dear All I found the solution;
A loop for automatic saving files..
it write every column in a matrix called mat, column by column You just choose the name of the exported files like "file' and chhose the folder, then the loop will save automatically all files like (file1.wav, file2.wav etc). You can use it for any other file types such as xls or txt, you will only have to change the write command like 'xlswrite" "dlmwrite" etc.
%Write ALL wave files
Fs=input('Enter The the sampling frequency (No. of samples/second) ='); % this will be used in the
frequency Axis
name = input('Enter File name? :','s');
Origin_Name= name ;
[file,path] = uiputfile('*.wav');
FileName = fullfile(path,file);
for i=1:n
FileName=[Origin_Name,num2str(i)];
wavwrite(mat(:,i),Fs,16,FileName);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by