Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fungtion smaller memory

Subject: fungtion smaller memory

From: wahyoe Unggul

Date: 18 Jun, 2010 10:19:05

Message: 1 of 5

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;

Subject: fungtion smaller memory

From: Roger Stafford

Date: 18 Jun, 2010 11:37:21

Message: 2 of 5

"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

Subject: fungtion smaller memory

From: wahyoe Unggul

Date: 18 Jun, 2010 23:44:04

Message: 3 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hvflph$pb4$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvfh6o$bls$1@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

Subject: fungtion smaller memory

From: Roger Stafford

Date: 19 Jun, 2010 00:24:05

Message: 4 of 5

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

Subject: fungtion smaller memory

From: wahyoe Unggul

Date: 20 Jun, 2010 05:02:05

Message: 5 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hvh2n5$smi$1@fred.mathworks.com>...
> "wahyoe Unggul" <wahyoe_slipnot@yahoo.co.id> wrote in message <hvh0c4$63l$1@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us