Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: fungtion smaller memory
Date: Fri, 18 Jun 2010 11:37:21 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 39
Message-ID: <hvflph$pb4$1@fred.mathworks.com>
References: <hvfh6o$bls$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1276861041 25956 172.30.248.37 (18 Jun 2010 11:37:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 18 Jun 2010 11:37:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:646093

"wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvfh6o$bls$1@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