|Nov29-12, 03:05 PM||#1|
MATLAB accumarray problem
Is anyone proficient in the use of accumarray?
I supply two vectors of same length, indices L,weights W, L positive integers as required.
I sort the indices to ascending.Then, the result of accumarray is not equal to unique(L).How could this be?
Code for illustration:
i = [46 47 47 46 48 49 48 48 48]'; w = 2*rand(size(i)); Y=[i';w']; [x y] = sort(Y(1,:)); Y = Y(:,y); Y,pause uw = accumarray((Y(1,:))',Y(2,:)'); ui = unique(i); numel(uw),numel(ui) --- OUTPUT : Y = 46.0000 46.0000 47.0000 47.0000 48.0000 48.0000 48.0000 48.0000 49.0000 1.5844 0.0714 1.9190 1.3115 1.6983 1.3575 1.5155 1.4863 1.8680 ans = 49 ans = 4
|Nov29-12, 07:26 PM||#2|
Blog Entries: 1
It took me a few passes to read through the documentation and understand it, but I think the key is where it explains what the function actually does (and then apply that to the first example).
When you apply accumarray to them, the first entry will be the sum of those elements with subscript 1, the second with subscript 2, and so on. Which is why the output array has a sum of zero for the third element (none of the elements of val were subscripted with three).
In your case:
I hope this helps in your understanding of what's going on in this portion of your work, because I don't have any experience with the larger problem that you're working on.
|Dec1-12, 12:11 PM||#3|
Yes i got it eventually.
In my example,to add you just use the weights
|Similar Threads for: MATLAB accumarray problem|
|MATLAB problem||Introductory Physics Homework||1|
|Matlab Problem||Engineering, Comp Sci, & Technology Homework||0|
|Matlab ODE problem||Math & Science Software||3|
|MATLab Problem||Math & Science Software||3|
|Another Matlab problem||Math & Science Software||4|