How to Save new data to existing structure data in a for loop without having to save the complete Matlab file from Zero?

5 views (last 30 days)
Hi all,
I am really not sure how to ask this!
I have daily coming data in which i am doing evaluation and saveing the results in .mat file (data is in a mixed structure form). the size of the saved data is getting bigger with time, and loading and saving the data for each loop is taking time. yet the structure form is not changeing only the size of some fileds inside that structre. how can i save only the new data like apped or join or add to the existing .mat file.??
so my structure is as following:
Changing fields size in the loop
DayData.Ppos = [];
DayData.Qpos = [];
DayData.Upos = [];
Non-Changing fields size in the loop
DayData.CP = "xxxxxxxxx";
DayData.RawDataName = {'XXX1','XXX2','YYY1','YYY2'};
My Loop then look something like this:
for ii = 1:(DayFinished)
Connections = 5;
for i = 1:Connections
% Load available data for this connection
DayData = load(sprintf('MyMfile%d.mat',i)); % this will load the DayData for Connection i
% Do calculations
%Ppos = .....
%Qpos = .....
% Join Old data to new Data
DayData.Ppos = [DayData.Ppos,Ppos];
% and so on with the append or join
% now save the data
so you can see i am just simply joining new data to old data and saving the results for later use.
I already read about "matfile" function which seems to me the soluation i am looking for but i did not manage to make it work, so any help is of a great value thanks in advance
Best Regards

Accepted Answer

Aubai on 28 Jul 2021
So after looking i did not get any answer that can be cosidered.
I can till you it is not possible for the matfile function to read structure arrays the data need to be saved seperatly.
I hope this my help someone in the future

More Answers (1)

J. Alex Lee
J. Alex Lee on 30 Jun 2021
I would consider using a database, a lightweight solution could be sqlite. I use the third party mksqlite for this purpose and it works quite well for me.


Find more on Environment and Settings in Help Center and File Exchange




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by