
October 26th, 2009, 09:21 PM
|
 | Grand Panjandrum | | Join Date: Nov 2005 Location: South of England
Posts: 12,260
Country: Thanks: 776
Thanked 3,982 Times in 3,214 Posts
| |
Quote:
Originally Posted by jalko Hi there,
I have problem with optimizing my code, I am no programmer so can't really see the way to make that computation faster. It will take days to complete all I need from it. I searched the web and as I understand there is multithreading constantly allowed in newer matlab versions, but I still get only about 27% working of that c2q which is doing it. I also used profiler, but gave me nothing useful. And also tried to use Parallel Computing toolbox, but when I set then error will show up. "??? Error: File: pohpriem.m Line: 33 Column: 9
The variable d in a parfor cannot be classified."
Can someone point me the way how to do this correctly or some other optimalization that code should have?
Here is the code: Code: function d=pohpriem(x, y)
matlabpool open local 2
[m1,n1]=size(x);
[m2, n2]=size(y);
c=m1-1;
i=0;
j=0;
for b=1:n1
for l=0:c;
for k=l+1:m1-1;
A=regexp(y{k},'\.','split');
D1=[str2num(A{1}) str2num(A{2}) str2num(A{3})];
sD1= datenum(D1);
B=regexp(y{k+1},'\.','split');
D2=[str2num(B{1}) str2num(B{2}) str2num(B{3})];
sD2=datenum(D2);
if sD1 < sD2;
break;
else
i=i+1;
j=j+1;
z(j,i)=log(x(m1-l,b))-log(x(m1-k,b));
end
end
end
[m3 n3]=size(z);
for a=1:n3;
l(a)=z(a,a);
d(b,a)=l(a);
end
z=0;
i=0;
j=0;
end
d=d';
Thanks for reading!
Tom. | What is the purpose of z? If this is a local variable you are dynamically redimensioning it within the innermost loop. If possible compute its final dimensions before entering any loop and initialise it with zeros(dim1,dim2).
Also you appear only to use the diagonal elements of z (in fact as far as I can tell you are only computing these). If so only compute the diagonal elements and use a vector for them not an array.
CB
__________________ Truth does not change because it is, or is not, believed by a majority of the people.
Giordano Bruno |