Okay... I'm 5 years late here... but I just did this for myself and wanted to put the solution out there!
I had the same issue with running out of memory while writing large wav files in matlab. I got around this by editing the matlab wavwrite function so it pulls data from your harddrive using memmap instead of variables stored on the RAM, then saving it as a new function. This will save you a lot of trouble, as you don't have to worry about dealing with headers when writing the wav file from scratch, and you wont need any external applications.
1) type edit wavwriteto see the code for the function, then save a copy of it as a new function.
2) I modified the y variable in the wavwrite function from an array containing the wav data to a cell array with strings pointing to the locations for the data of each channel saved on my harddrive. Use fwrite to store your wav data on the harddrive first of course. At the beginning of the function I transformed the file locations stored in y into memmap variables and defined the number of channels and samples like so:
replace these lines:
% If input is a vector, force it to be a column:
if ndims(y) > 2,
error(message('MATLAB:audiovideo:wavwrite:invalidInputFormat'));
end
if size(y,1)==1,
y = y(:);
end
[samples, channels] = size(y);
with this:
% get num of channels
channels = length(y);
%Convert y from strings pointing to wav data to mammap variables allowing access to the data
for i = 1:length(y)
y{i} = memmapfile(y{i},'Writable',false,'Format','int16');
end
samples = length(y{1}.Data);
3) Now you can edit the private function write_wavedat(fid,fmt). This is the function that writes the wav data. Turn it into a nested function so that it can read your y memmap variable as a global variable, instead of passing the value to the function and eating up your RAM, then you can make some changes like this:
replace the lines which write the wav data:
if (fwrite(fid, reshape(data',total_samples,1), dtype) ~= total_samples),
error(message('MATLAB:audiovideo:wavewrite:failedToWriteSamples'));
end
with this:
%Divide data into smaller packets for writing
packetSize = 30*(5e5); %n*5e5 = n Mb of space required
packets = ceil(samples/packetSize);
% Write data to file!
for i=1:length(y)
for j=1:packets
if j == packets
fwrite(fid, y{i}.Data(((j-1)*packetSize)+1:end), dtype);
else
fwrite(fid, y{i}.Data(((j-1)*packetSize)+1:j*packetSize), dtype);
end
disp(['...' num2str(floor(100*((i-1)*packets + j)/(packets*channels))) '% done writing file...']);
end
end
This will incrementally copy the data from each memmap variable into the wavfile
4) That should be it! You can leave the rest of the code as is, as it'll write the headers for you. Heres an example of how you'd write a large 2 channel wav file with this function:
wavwriteModified({'c:\wavFileinputCh1' 'c:\wavFileinputCh2'},44100,16,'c:\output2ChanWavFile');
I can verify this approach works, as I just wrote a 800mB 4 channel wav file with my edited wavwrite function, when matlab usually throws an out of memmory error for writing wav files larger then 200mb for me.