Running out of memory in a not so big matrix

2 次查看(过去 30 天)
i wrote a program to extract data from various files and for some reason ~10% of them give me a "Maximum variable size allowed by the program is exceeded" error. The matrices in the ones that don't work aren't bigger than the ones that do work (less than a 500x10000 matrix). The code basically looks like this:
tempsave=zeros(c.trials,9900);
accumulate=0;
for j=1:c.trials %e.g. 398 trials
spikes_in_trial=c.spike_end(j)-c.spike_start(j)+1; %find spikes in this trial
accumulate=spikes_in_trial+accumulate; %total spikes for cell
for k=accumulate-spikes_in_trial+1:accumulate
tempsave(j,c.spikes(k))=1000; %1000 to convert to Hz %error occurs here at j=241 , k=24023
end
end
%where in this example c.trials is [398], c.spike_start is [398x1], c.spike_end is [398x1] and c.spikes is [42004x1]
Even when I try and divide this into 2 separate for loops (for j=1:c.trials/2) I get the same error at the exact same point (trial 241).
I tried all types of solutions that worked for other people to no avail. Any ideas?
Oh and for what it's worth my memory stats: Maximum possible array: 1176 MB (1.233e+009 bytes) Memory available for all arrays: 2550 MB (2.674e+009 bytes) * Memory used by MATLAB: 276 MB (2.899e+008 bytes) Physical Memory (RAM): 3510 MB (3.681e+009 bytes)

采纳的回答

the cyclist
the cyclist 2011-9-23
I suggest you breakpoint your code (using conditional breakpointing) just before the line that fails, at j==241, k==24023. Then look at the values and sizes of your variables.
What is the value of c.spikes(24023), which is being used as an index? My best guess is that that value is large (e.g. much larger than 10,000), which is why you are getting that specific error.
  1 个评论
John
John 2011-9-23
You're totally right. You'd think I'd have looked there but for some reason I was thinking I'd have gotten an "Index Exceeds Matrix Dimensions" error. There must be some bug in the code since the c.spikes looked like this:
3256
3260
3280
3300
3322
3323
3332
218107163
3365
896
929
952
965
968
999
1009
1019
1022
Sorry I'm an idiot. Thanks for the help guys :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by