From: Walter Roberson on
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?
From: wahyoe Unggul on
Walter Roberson <roberson(a)hushmail.com> wrote in message <G9WSn.1$Yo5.0(a)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
From: Walter Roberson on
wahyoe Unggul wrote:

> 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);

Either of those *replace* the loop. The first of them can be used if
there are no cases in which [tA(i,2),tA(i,2)] == [tA(k,2),tA(k,2)] for
some i and k. The second of them should work (I think) in the case where
there are repeated pairs.
From: wahyoe Unggul on
Walter Roberson <roberson(a)hushmail.com> wrote in message <aR3Tn.8779$1Q5.2332(a)newsfe08.iad>...
> wahyoe Unggul wrote:
>
> > 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);
>
> Either of those *replace* the loop. The first of them can be used if
> there are no cases in which [tA(i,2),tA(i,2)] == [tA(k,2),tA(k,2)] for
> some i and k. The second of them should work (I think) in the case where
> there are repeated pairs.
==================================================
case back to the beginning of the function if the C and B influence on the loop, how to modify the loop in order to complete the matrix that is big enough?
From: Walter Roberson on
wahyoe Unggul wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
> <aR3Tn.8779$1Q5.2332(a)newsfe08.iad>...
>> wahyoe Unggul wrote:
>>
>> > 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);
>>
>> Either of those *replace* the loop. The first of them can be used if
>> there are no cases in which [tA(i,2),tA(i,2)] == [tA(k,2),tA(k,2)] for
>> some i and k. The second of them should work (I think) in the case
>> where there are repeated pairs.
> ==================================================
> case back to the beginning of the function if the C and B influence on
> the loop, how to modify the loop in order to complete the matrix that is
> big enough?

I do not understand your question, sorry.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Alternative for matrix inverse?
Next: Library error