From: Marios Karaoulis on
I have this algorithm,

k=sparse(num1,num2)
k(5,5)=20;
.....

for i=1:num1
fog j=1:num2
k(i,j)=k(i,j)+val;
end
end

I want to speeed up things so, i just use the indexing of the matrix
like

tmp1=1;
for i=1:num1
fog j=1:num2
index(tmp1)=i;
index(tmp1)=j;
val(tmp1)=val
end
end

if i use k=sparse(index1,index2,val,num1,num2);

how can i tell matlab that in each k(i,j) add the val plus what it
already has in this position?

Marios
From: Bruno Luong on
Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <b414d116-6c68-4468-b22a-455dcb61ff81(a)32g2000prq.googlegroups.com>...

> if i use k=sparse(index1,index2,val,num1,num2);
>
> how can i tell matlab that in each k(i,j) add the val plus what it
> already has in this position?

Not sure if I understand your question, but SPARSE DOES accumulate the values val at the same position index1 and index2.


>> sparse([1 1],[1 1],[2 3])

ans =

(1,1) 5

>>

% Bruno
From: Marios Karaoulis on
On Jun 5, 1:11 am, "Bruno Luong" <b.lu...(a)fogale.findmycountry> wrote:
> Marios Karaoulis <marios.karaou...(a)gmail.com> wrote in message <b414d116-6c68-4468-b22a-455dcb61f...(a)32g2000prq.googlegroups.com>...
> > if i use k=sparse(index1,index2,val,num1,num2);
>
> > how can i tell matlab that in each k(i,j) add the val plus what it
> > already has in this position?
>
> Not sure if I understand your question, but SPARSE DOES accumulate the values val at the same position index1 and index2.
>
> >> sparse([1 1],[1 1],[2 3])
>
> ans =
>
>    (1,1)        5
>
>
>
> % Bruno

Thanks, Bruno. This is exactly what I asked .
Lately, you have answered a lot of my questions, so thank you again