I have Matlab R2012a installed on my own computer and Matlab R2009a (multi thread) installed on my friend’s computer. Because of the reason that my computer has only 2gb ram whereas my friend’s has 128gb and a better processor, I decided to execute my code on my friend’s computer.
I connected to his computer with a remote desktop connection program, downloaded my code and dataset from dropbox and executed my code. However, my code’s execution did not finish even though an hour passed. (It took about 20 minutes on my computer and if you think that my friend’s system is much more better than mine, it should have taken less than 20 minutes.) Then I waited a few hours more but execution did not finish.
Then, to understand where the problem is, I evaluated the code step by step by hand and noticed that it could not finish the execution of the following loop:
l=1;
for n=1:max_t
for m=1:t(1,n).numberofPoints
x_t(l)=t(1,n).matrix(m,1);
y_t(l)=t(1,n).matrix(m,2);
z_t(l)=t(1,n).matrix(m,3);
l=l+1;
end
end
minx = min(x_t(:));
miny = min(y_t(:));
minz = min(z_t(:));
It is just a simple loop to obtain my minimum point in x,y,z coordinates. (I am sure there is nothing wrong with this loop. It works successfully on my PC.) I know I do not need loops to obtain maximum and minimum points of a struct but I am new to MATLAB and do not know much. Therefore it seemed like the easiest option to me.
I really have to be able to use my friends’ computer because my ram will not be enough for the further process. Therefore I need to solve this problem.
What can be the reason that same code works on my computer but not on my friends’ computer?
Matlab R2011a introduced dramatic performance improvements when growing arrays in a loop, and I believe R2012a improved those even further.
Thus, in R2009, the loop simply takes a lot longer to run, since you’re not pre-allocating
x_t.There are other ways to improve your code as well, here I’ll simply fix the preallocation: