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 Center および File ExchangeWorkspace 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