accumarray documentation(adsbygoogle = window.adsbygoogle || []).push({});

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 get 49 weight vectors for the 9 indices, the unique of which are 4!Code (Text):

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

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB accumarray problem

Loading...

Similar Threads - MATLAB accumarray problem | Date |
---|---|

How to program this in Matlab | Feb 28, 2018 |

Matlab Making a short test for self-adjointness | Feb 23, 2018 |

Matlab Plotting Coordinate Transformations in Matlab | Feb 12, 2018 |

Does anyone had this plotting problem with MATLAB? | Dec 23, 2017 |

**Physics Forums - The Fusion of Science and Community**