Prev: Fmincon
Next: Linear regression simple problem
From: Luna Moon on 25 Jun 2010 14:11 K>> subs = [1; 2; 4; 2; 4]; A = accumarray(subs, 101:105) A = 101 206 0 208 Why is that? I just don't get it...
From: Sean on 25 Jun 2010 14:24 Luna Moon <lunamoonmoon(a)gmail.com> wrote in message <f85233fc-b174-48a9-be24-f4fdaf2d5a67(a)e5g2000yqn.googlegroups.com>... > K>> subs = [1; 2; 4; 2; 4]; > A = accumarray(subs, 101:105) > > A = > > 101 > 206 > 0 > 208 > > Why is that? I just don't get it... Every time a sub encountered it's corresponding value is added. (The default function is plus) Thus there is one 1 summing to 101. 2 sums 102,104 = 206;4 sums 103,105=208. There are no 3s so it doesn't get anything.
From: Matt Fig on 25 Jun 2010 14:28 For this simple case, % DATA subs = [1; 2; 4; 2; 4]; val = [101;102;103;104;105]; % ENGINE A = zeros(max(subs),1); for ii = 1:length(subs) A(subs(ii)) = A(subs(ii)) + val(ii); end
|
Pages: 1 Prev: Fmincon Next: Linear regression simple problem |