|
Walter Roberson <roberson@hushmail.com> wrote in message <G9WSn.1$Yo5.0@newsfe01.iad>...
> wahyoe Unggul wrote:
> > I do not use Matlab profiler, I calculate the time to execute a matrix
> > with the manual, I think there is an error function "assembly", when
> > entering data (matrix) small size can be executed quickly but instead,
> > jiak data (matrix) large size is very slow (time old) to be executed,
> > can you help to correct the above functions so that data (matrix) which
> > can be executed with large quick times
>
> It appears I have to repeat myself as you are having trouble finding my
> previous posting:
>
> === begin what I already posted ===
>
> Is it correct that you do not care what the values of B and C are after
> the loop? If so then your loop becomes
>
> for i = 1:length(tA)
> A(tA(i,2),tA(i,3)) = tA(i,1) + A(tA(i,2),tA(i,3));
> end
>
> Which can be optimized to a plain vector calculation as
>
> T = sub2ind(size(A),tA(i,2),tA(i,3));
> A(T) = A(T) + tA(:,1);
>
>
> If, though, the tA(i,2),tA(i,3) pairs might be duplicated, then
>
> T = sub2ind(size(A),tA(i,2),tA(i,3));
> T1 = accumarray(T,tA(:,1));
> T2 = unique(T);
> A(T2) = A(T2) + T1(T2);
>
>
> === end what I already posted ===
>
> Your existing code does a lot of needless copying.
>
> Your existing code does not pre-allocate memory properly for the case
> where max(tA(:,3)) is greater than max(tA(:,2))
>
> *Are* duplicate pairs of tA(i,2), tA(i,3) possible, or is every pair unique?
+++++++++++++++++++++++++++++++++++++++++++++++++
very-very fantastic
thank ypu very^2 much
of B and C do not affect the function or loop
after replacing my script
for i=1:length(tA);
> C=A;
> B(tA(i,2),tA(i,3))=tA(i,1);
> A(tA(i,2),tA(i,3))=B(tA(i,2),tA(i,3))+C(tA(i,2),tA(i,3));
> end;
into this script
for i = 1:length(tA)
> A(tA(i,2),tA(i,3)) = tA(i,1) + A(tA(i,2),tA(i,3));
> end
very^2 fantastic
I once had to wait hours to complete the data (matrix) are large, now less than a minute I got some results
whether additional below inserted after the "end" or between "for" and "end"?
T = sub2ind(size(A),tA(i,2),tA(i,3));
> A(T) = A(T) + tA(:,1);
>
> or
> T = sub2ind(size(A),tA(i,2),tA(i,3));
> T1 = accumarray(T,tA(:,1));
> T2 = unique(T);
> A(T2) = A(T2) + T1(T2);
thanks before
|