MATLAB code actually runs quick but command window response takes too long with large cell variable
Ältere Kommentare anzeigen
Hi, I'm running MATLAB 2021a, on windows 10 Pro (and I have more than enough RAM and CPU power).
An issue I'm running into is that debugging my current project's code is annoying, as it takes way too long to get a response, and I've narrowed it down to it being related to one variable that I have. This variable is kind of like this (i know the code isn't correct, but just trying to get the point across):
a = cell(600,1);
for i = 1:30
load('bXXX.mat', 'b'); % XXX goes from 001 to 600
a{i} = b;
end
Where each b is different, and each is a cell of its own, i.e., each b = cell(7000,1);
And each cell of b is a struct, each of which has about 20 variables, some of which are datetimes (including NaT), and some are character arrays and some are scalar doubles. If I do 'whos', then the total size is 949,844,244 for variable a, which is not that much, but it includes 30x7000 cells, each of which includes a struct of 20 variables. EDIT:(I know that a{31:600} are basically empty). END-EDIT
The problem is, if this variable is in the workspace, then if I simply do something as simple as
g = 3;
in the command window, while it will execute instantenously, the command window prompt won't be available for at least 5 seconds.
I looked at some other posts suggesting this could have something to do with the Workspace tab. I tried to close it, but it didn't help at all. Maybe something in the workspace settings might help?
Thanks for any help. It's really annoying trying to debug like this, when every time I enter something in the command window, it takes a minimum of 5 seconds, sometimes even minutes. It's also the same if I try to add/remove breakpoints. Sometimes also slow when I open certain code files in the matlab editor.
EDIT2:
some random code you can replicate with. Run the following first, then after it finishes, quickly do g = 3; repeteadly on command window (press up button and enter after you type it once)
a = cell(600,1);
sdate = datetime(2003,1,1);
for i = 1:30
b = cell(7000,1);
for j = 1:7000
if(rand(1) < 0.9)
b{j}.Dataset = 'randomdataset';
b{j}.Name = 'AGULD';
b{j}.Num = i;
b{j}.Active = false;
b{j}.Day = j;
CurrentDatetime = sdate + days(j);
DateNow = CurrentDatetime.Year*10000 + CurrentDatetime.Month*100 + CurrentDatetime.Day;
b{j}.DateNow = DateNow;
b{j}.Datetime1 = CurrentDatetime;
b{j}.Datetime2 = CurrentDatetime;
b{j}.DatetimeOffsetSeconds = 0;
b{j}.var1 = 1;
b{j}.var2 = 1;
b{j}.var3 = 1;
b{j}.vars1 = 1;
b{j}.vars2 = 1;
b{j}.Datetime5 = CurrentDatetime;
b{j}.Datetime5correct = CurrentDatetime;
b{j}.Datetime5Datenum = 1;
b{j}.Datetime5OffsetSeconds = 0;
b{j}.vars3 = 1;
b{j}.vars4 = 1;
b{j}.vars5 = 1;
b{j}.vars6 = 1;
b{j}.vars7 = 1;
b{j}.vars8 = 0;
b{j}.vars9 = 0;
b{j}.Direction = 'up';
b{j}.vars10 = 0;
else
b{j}.Dataset = 'randomdataset';
b{j}.Name = 'AGULDRODOT';
b{j}.Num = i;
b{j}.Active = false;
b{j}.Day = j;
CurrentDatetime = sdate + days(j);
DateNow = CurrentDatetime.Year*10000 + CurrentDatetime.Month*100 + CurrentDatetime.Day;
b{j}.DateNow = NaT;
b{j}.Datetime1 = NaT;
b{j}.Datetime2 = NaT;
b{j}.DatetimeOffsetSeconds = 0;
b{j}.var1 = 1;
b{j}.var2 = 1;
b{j}.var3 = nan;
b{j}.vars1 = nan;
b{j}.vars2 = nan;
b{j}.Datetime5 = NaT;
b{j}.Datetime5correct = NaT;
b{j}.Datetime5Datenum = 1;
b{j}.Datetime5OffsetSeconds = 0;
b{j}.vars3 = 1;
b{j}.vars4 = 1;
b{j}.vars5 = 1;
b{j}.vars6 = 1;
b{j}.vars7 = 1;
b{j}.vars8 = 0;
b{j}.vars9 = 0;
b{j}.Direction = 'up';
b{j}.vars10 = 0;
end
end
a{i} = b;
end
6 Kommentare
Bruno Luong
am 20 Okt. 2021
What if you do
pack
after reading the data?
Konstantinos Georgiadis
am 20 Okt. 2021
Bruno Luong
am 20 Okt. 2021
Bearbeitet: Bruno Luong
am 20 Okt. 2021
No problem to me (R2021b, PC with 32 Gb of RAM)
>> YourScipt
>> toto
>> tic; g=3; toc
Elapsed time is 0.000204 seconds.
>> whos
Name Size Bytes Class Attributes
CurrentDatetime 1x1 8 datetime
DateNow 1x1 8 double
a 600x1 1021867150 cell
b 7000x1 34061960 cell
g 1x1 8 double
i 1x1 8 double
j 1x1 8 double
sdate 1x1 8 datetime
>> memory
Maximum possible array: 31243 MB (3.276e+10 bytes) *
Memory available for all arrays: 31243 MB (3.276e+10 bytes) *
Memory used by MATLAB: 3305 MB (3.466e+09 bytes)
Physical Memory (RAM): 32670 MB (3.426e+10 bytes)
* Limited by System Memory (physical + swap file) available.
>> ver
-----------------------------------------------------------------------------------------------------
MATLAB Version: 9.11.0.1769968 (R2021b)
MATLAB License Number: xxxxxx
Operating System: Microsoft Windows 8.1 Pro Version 6.3 (Build 9600)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
-----------------------------------------------------------------------------------------------------
MATLAB Version 9.11 (R2021b)
MATLAB Coder Version 5.3 (R2021b)
MATLAB Compiler Version 8.3 (R2021b)
Optimization Toolbox Version 9.2 (R2021b)
Signal Processing Toolbox Version 8.7 (R2021b)
>>
Konstantinos Georgiadis
am 20 Okt. 2021
Bruno Luong
am 20 Okt. 2021
I have observed no of such latency problem.
Everything is OK.
Konstantinos Georgiadis
am 20 Okt. 2021
Antworten (0)
Kategorien
Mehr zu Logical finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!