MATLAB code actually runs quick but command window response takes too long with large cell variable

8 vues (au cours des 30 derniers jours)
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 commentaires
Bruno Luong
Bruno Luong le 20 Oct 2021
I have observed no of such latency problem.
Everything is OK.
Konstantinos Georgiadis
Konstantinos Georgiadis le 20 Oct 2021
ok I made a video of what it does:
https://www.youtube.com/watch?v=vJu7tPg_rm4

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by