1

I m creating .wav file in every iteration of for loop and that .wav files are stored in the current directory where I am working on .Now I want to create a folder in current directory and each created file should get store in the created folder in each iteration...

for i=1:size(seg_data(:,1))
    w(i,:)=data(seg_data(i,1): seg_data(i,2));
    wavwrite(w(i,:),['file_',num2str(i)]);
end
user3168654
  • 95
  • 1
  • 11

1 Answers1

2

You should use mkdir to create the new directory (once).
Then you should provide the relative path to the new folder to wavwrite

subFolderName = 'mySubFolder'; % for example
mkdir( subFolderName ); % if folder exists, a warning is issued
for ii=1:size( seg_data, 1 )
    % ... do your stuff here
    wavwrite( w(ii,:), fullfile( subFolderName, sprintf( 'file_%d', ii ) ) );
end

Note the use of fullfile to create path string - works for windows as well as linux paths.

PS,
It is best not to use i as a variable name in Matlab.

Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371