Saving data using string filenames in MATLAB
It is an easy matter to save data as a mat(MATLAB binary) file or an ASCII file so long as you know the filename beforehand. For ex: to save data in the variable
If you have multiple columns of data, just ensure that
datvar to a file mydata.dat, all you have to do is say
save mydata.dat datvarHowever if you want to dynamically generate your filename, things get a little tricky since MATLAB's documentation is sparse about this. Here's how:
% Create a filename (myfile.001) using sprintf
fOut = sprintf('myfile.%03d',i); % say, i=1
% save data as an ASCII file
save(fOut, 'datvar', '-ascii');
% Or, create a mat file - (myfile001.mat)
% since MATLAB binary files typically have the extension .mat
fOut = sprintf('myfile%03d.mat',i); % say, i=1
% save data as matlab binary
save(fOut, 'datvar');
If you have multiple columns of data, just ensure that
datvar is an array. Remember that the .mat file will retain the name of the variable datvar but the ASCII file will only contain data.