MATLAB: Saving a 2D matrix each loop iteration as a specific file type and name

each iterationnaming conventionsave arraysave matrixvarying length

Hi All, I've had a look at the other answers in the community and none seem to work for me, so here is my problem. In a for-loop, I'm uploading a series of audio files one at a time, reading it as wav data, performing calculations on it (RMS in this case) and then want to save both the y matrix (varying size, 2D) and the RMS array (varying length) each loop iteration, with a specific naming convention.
My code is below:
%Load files
%Define working folder
myfolder = 'H:\ERP2018\Actor 01 Normal Intensity Only;
myDir = 'H:\ERP2018\Actor 01 Normal Intensity Only; %gets directory
myFiles = dir(fullfile(myDir,'*.wav')); %table of file names, size, etc
%forloop
for k = 1:length(myFiles)
baseFileName = myFiles(k).name;
FileName=[baseFileName,num2str(baseFileName)] ;
fullFileName = fullfile(myfolder, baseFileName);
[wavData, Fs] = audioread(fullFileName);
y=wavData; %want to save this each loop through

%split into frames and save as 2D matrix
FrameLen=512;
%gives a frame length of 10.69ms approx
FramesMat= buffer(y, FrameLen);
FramesMat = FramesMat';
%gives matrix of 512 samples by a varying number of frames (about 227 frames)
RMSFramesMat = rms (FramesMat); %want to save this each loop through
end
In each loop, I want to save the y matrix, named as 'originalactor01-k' where k is an incremental as the loop runs, and want to save the RMSFramesMat as an array named 'RMSFramesMatactor01-k'
Ideally, as an excel readable file, unless there are better options, as this will be the basis of a stat analysis for my research. Any help that could be given would be great!
Thanks! Chris

Best Answer

How about using save() to save them in a .mat file? Otherwise simply use xlswrite(). Not sure where your difficulty in calling either of those functions lies. Doesn't even look like you tried to call either of them for some reason.
fullMatFileName = fullfile(myfolder, [baseFileName, '.mat']);
save(fullMatFileName, 'RMSFramesMat', 'y');
or something like
fullExcelFileName = fullfile(myfolder, [baseFileName, '.xlsx']);
xlswrite(fullExcelFileName, RMSFramesMat, 'Results', 'A1');
xlswrite(fullExcelFileName, y, 'Results', 'A2');