matlab - Is there an array creation function for full arrays that has the same signature as sparse matrix constructor? -


i'd accumulate indexed elements in matrix, table , tapply function in r.

i found sparse(i,j,s,m,n) fit need perfectly,

as document says:"any elements of s have duplicate values of , j added together."

but have convert obtained sparse matrix full 1 using full():

a = a + full(sparse(i,j,s,m,n)); 

is efficient way so?


by way, there below, no matter whether adding duplicated i,j pairs?

a = setelements(a, i,j,s); 

and

vector = getelement(a,i,j); 

where i&j take meanings in sparse() function.


and if multidimensional array? sparse() deal matrix. have set entries page page outer loops?

take @ accumaray. example,

ii = [1 2 2 3 3]; jj = [3 2 2 2 2]; s = [10 20 30 40 50]; = accumarray([ii(:) jj(:)],s(:)); 

gives

a =       0     0    10      0    50     0      0    90     0 

note each row of first argument ([ii(:) jj(:)]) defines n-dimensional index output array (n 2 in example).

accumarray flexible. works n-dimensional arrays, lets specify size of result (it may larger inferred supplied indices), , can apply arbitrary function (different sum) each set of values defined same index.

as more general example, above data,

a = accumarray([ii(:) jj(:)],s(:),[4 4],@max) 

gives

a =       0     0    10     0      0    30     0     0      0    50     0     0      0     0     0     0 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -