Performance issues with writing into matfiles

조회 수: 1 (최근 30일)
Peter Valent
Peter Valent 2022년 2월 4일
댓글: Srija Kethiri 2022년 2월 25일
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;

답변 (1개)

Srija Kethiri
Srija Kethiri 2022년 2월 18일
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
Peter Valent
Peter Valent 2022년 2월 18일
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 2022년 2월 25일
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!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by