From: wahyoe Unggul on
Can you help me, can function under these modified to use smaller memory
===========================================
% Purposes
% This function assembly matrix base on row and col.
% information
% For example take matrices
% A1=[0.178857384;0.57896014;0.635206968;0.437880448]
% A2=[0.389532694;0.449666857;0.821290467;0.105003395]
% A3=[0.164485174;0.351283287;0.682633129;0.956467906]
% with index
% iA1=[1 1;1 2;2 1;2 2]
% iA2=[2 2;2 3;3 2;3 3]
% iA3=[3 3;3 4;4 3;4 4]
% The result is
% A=[0.178857384 0.57896014 0 0
% 0.635206968 0.827413142 0.449666857 0
% 0 0.821290467 0.269488569 0.351283287
% 0 0 0.682633129 0.956467906]
% tA=[A1 iA1;A2 iA2;A3 iA3]

function [A]=assembly;

load scratch_file.txt;
tA=scratch_file;clear scratch_file;
m=max(tA(:,2));
A=zeros(m,m);
%B=zeros(size(tA));
B=A;C=A;
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;
delete scratch_file.txt;
From: Roger Stafford on
"wahyoe Unggul" <wahyoe_slipnot(a)yahoo.co.id> wrote in message <hvfh6o$bls$1(a)fred.mathworks.com>...
> Can you help me, can function under these modified to use smaller memory
> ===========================================
> % Purposes
> % This function assembly matrix base on row and col.
> % information
> % For example take matrices
> % A1=[0.178857384;0.57896014;0.635206968;0.437880448]
> % A2=[0.389532694;0.449666857;0.821290467;0.105003395]
> % A3=[0.164485174;0.351283287;0.682633129;0.956467906]
> % with index
> % iA1=[1 1;1 2;2 1;2 2]
> % iA2=[2 2;2 3;3 2;3 3]
> % iA3=[3 3;3 4;4 3;4 4]
> % The result is
> % A=[0.178857384 0.57896014 0 0
> % 0.635206968 0.827413142 0.449666857 0
> % 0 0.821290467 0.269488569 0.351283287
> % 0 0 0.682633129 0.956467906]
> % tA=[A1 iA1;A2 iA2;A3 iA3]
>
> function [A]=assembly;
>
> load scratch_file.txt;
> tA=scratch_file;clear scratch_file;
> m=max(tA(:,2));
> A=zeros(m,m);
> %B=zeros(size(tA));
> B=A;C=A;
> 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;
> delete scratch_file.txt;

Check out accumarray.

Roger Stafford
From: wahyoe Unggul on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hvflph$pb4$1(a)fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot(a)yahoo.co.id> wrote in message <hvfh6o$bls$1(a)fred.mathworks.com>...
saya sudah mengeceknya, bila matriks yang sy gunakan tidak terlalu besar maka fungsi ini dapat berjalan dengan cepat, sedangkan jika matriks besar yang saya gunakan fungsi ini berjalan dengan lambat
From: Roger Stafford on
"wahyoe Unggul" <wahyoe_slipnot(a)yahoo.co.id> wrote in message <hvh0c4$63l$1(a)fred.mathworks.com>...
> saya sudah mengeceknya, bila matriks yang sy gunakan tidak terlalu besar maka fungsi ini dapat berjalan dengan cepat, sedangkan jika matriks besar yang saya gunakan fungsi ini berjalan dengan lambat
................
Translation, courtesy of Google:
I have checked, if the matrix of the sy using is not too large, this function can be moved quickly, whereas if a large matrix that I use this function will be slow
- - - - - - - - - -
Hmm! That surprises me. The accumarray function is designed to do precisely this kind of processing and it should be faster than that for-loop you used in the "assembly" function. Also it would require less memory. Actually you do not need those B and C matrices in your function. You can add tA directly into A without them.

Roger Stafford
From: wahyoe Unggul on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hvh2n5$smi$1(a)fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot(a)yahoo.co.id> wrote in message <hvh0c4$63l$1(a)fred.mathworks.com>...
> > saya sudah mengeceknya, bila matriks yang sy gunakan tidak terlalu besar maka fungsi ini dapat berjalan dengan cepat, sedangkan jika matriks besar yang saya gunakan fungsi ini berjalan dengan lambat
> ...............
> Translation, courtesy of Google:
> I have checked, if the matrix of the sy using is not too large, this function can be moved quickly, whereas if a large matrix that I use this function will be slow
> - - - - - - - - - -
> Hmm! That surprises me. The accumarray function is designed to do precisely this kind of processing and it should be faster than that for-loop you used in the "assembly" function. Also it would require less memory. Actually you do not need those B and C matrices in your function. You can add tA directly into A without them.
>
> Roger Stafford
thank you