MATLAB: What is wrong with the code

feature extractionMATLABsave

I have created an imagearray consisting of 434 images, then extracted features from this imagearray using a function, now i want to store these features in a file in append mode.But when i do the last bit that is storing the features in a file i get an error.
for i=1:length(imagefile)
%images store in a variable imgarray
%Extracting features
fea=waveletfea(imgarray);
%Storing features
save('feature.mat','fea','-append');
end
error:
Unable to write MAT file
file may be corrupt
error in save('feature.mat','fea','append');
Any suggestions would be very helpful.Thanks in advance.

Best Answer

I'd store the results into a cell array or regular array and then just write out the array with one call to save() after the loop exits.
for k = 1 : n
% Code to read in imgarray, then...
fea{k} = waveletfea(imgarray);
end
folder = pwd;
baseFileName = 'feature.mat';
fullFileName = fullfile(folder, baseFileName);
save(fullFileName,'fea');
but first you have to make sure you have write access to the folder.