Performance issues with writing into matfiles

4 Ansichten (letzte 30 Tage)
Peter Valent
Peter Valent am 4 Feb. 2022
Kommentiert: Srija Kethiri am 25 Feb. 2022
I am writing a simulation program that uses multiple long time series of substantial length. To avoid memory overflow I read the data from the predefined text files and store them on disk in a mat file. When writing datetime data into the matfiles I have encountered several issues with performance. The performance issues were quite significant as sometime it took less than 1s and sometimes ~300s.
Has anyone else observed similar performance issues? Could it be related to the datatime data type?
% Here is simple code snippet
dt = (datetime(1,1,1):datetime(3000,12,31))';
m = matfile('test.mat','Writable',true);
m.dt = dt;

Antworten (1)

Srija Kethiri
Srija Kethiri am 18 Feb. 2022
Hi Peter,
You are getting this issue because of the matfile so delete the matfile before you write into it.
The attached code might be helpful:
delete('test.mat');
dt = (datetime(1,1,1):datetime(3000,12,31))';
m = matfile('test.mat','Writable',true);
m.dt = dt;
You can refer to the following link to know more about,
  2 Kommentare
Peter Valent
Peter Valent am 18 Feb. 2022
I cannot delete the matfile before I write the datetime variable into it as the file already contains other data that will be used later on. I am using the matfile to store data that would not necessarily fit into memory.
Srija Kethiri
Srija Kethiri am 25 Feb. 2022
Hi Peter,
From my understanding you can’t delete the file as the file already contains other data. The data in matfile is large to fit in memory.
So, you can load the data present in the matfile to the variables in workspace, as the data is large, the best practice is to read and write as much data into memory as possible at a time. Otherwise, repeated file access negatively impacts the performance of your code. You can use the load function to do it. And then after deleting the file rewrite this data into the same matfile.
For more information about loading parts of variables from matfile refer to this documentation: Save and Load Parts of Variables in MAT-Files - MATLAB & Simulink (mathworks.com)
Hope this helps!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by