MATLAB: How to append new structure array element in existing .mat file.

MATLABsave

I am appending new structure array element in existing .mat file (which contains structures), it saves new element accurately but previous values are replaced with empty elements. as stated below
FileName=fullfile('\\Server Location Address');% Address of existing .mat file
Device(5)=struct('A',1,'B',2,'C',3);
save(FileName,'Device','-append');
The above code save Device(5) elements accurately but it removes all Devices values before 5.
Please help how to append new value in .mat file while don't changing previous ones.
Thanks

Best Answer

You might find that matfile is the easiest way. There are lots of examples and help in the documentation, but depending on your data something like this should work:
m = matfile(filename,'Writable',true);
m.device = [m.device,newdata];
or perhaps
m = matfile(filename,'Writable',true);
m.device(end+1) = newdata;