Hasan Haj
Hasan Haj

Reputation: 83

save a sound file in specific folder using matlab

I'm recording a sound and using wavwrite to save the wav file, but I need to save it in a specific folder in C:, such as in c:\Users\soundwav.

Here is an excerpt from my wavwrite code:

data(:,s)=getdata(ai,44100); 
y = [y; data]
         format shortg
         c = clock;
         fix(c);
         a=num2str(c);
         year=strcat(a(1),a(2),a(3),a(4),a(5));
         month=strcat(a(19),a(20));
         day=strcat(a(34),a(35));
         hour=strcat(a(48),a(49));
         min=strcat(a(63),a(64));
         sec=strcat(a(74),a(75));
         name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec);
         wavwrite(data,name);

Upvotes: 1

Views: 905

Answers (2)

il_raffa
il_raffa

Reputation: 5190

To select the folder in which to save your file, you can use uigetdir which allows you to select the folder; then you can add to it the filename you've built.

directoryname = uigetdir

You can also specify a starting folder

directoryname = uigetdir('c:\user\')

name = strcat(directoryname, '\', name);

Hope this helps.

Upvotes: 1

Hassan Saqib
Hassan Saqib

Reputation: 2757

You need to cd the path while saving it. I have included a line that concatenates the full path with name variable and then saves it.

         data(:,s)=getdata(ai,44100); 
         y = [y; data]
         format shortg
         c = clock;
         fix(c);
         a=num2str(c);
         year=strcat(a(1),a(2),a(3),a(4),a(5));
         month=strcat(a(19),a(20));
         day=strcat(a(34),a(35));
         hour=strcat(a(48),a(49));
         min=strcat(a(63),a(64));
         sec=strcat(a(74),a(75));
         name=strcat(year,'-',month,'-',day,'-',hour,'-',min,'-',sec);
         name = strcat('c:\Users\soundwav\', name);
         wavwrite(data,name);

Upvotes: 1

Related Questions