Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
accumarray issue (not working with large numbers?)

Subject: accumarray issue (not working with large numbers?)

From: Larry Rose

Date: 24 Aug, 2013 00:18:05

Message: 1 of 3

hey all,
this here works:
B = [1 2 3
1 3 4
2 2 2
3 4 5
3 3 3
3 5 9
4 8 9]

[unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]

But, if I change matrix B's left column to these large numbers I get error.
so this below does not work:
format long
 B = [20120101 2 3
20120101 3 4
20120102 2 2
20120103 4 5
20120103 3 3
20120103 5 9
20120104 8 9]

[unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]


Here is the error message:

??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> accumarray_issue at 22
[unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]
 

Thanks a lot,
Larry

Subject: accumarray issue (not working with large numbers?)

From: Bruno Luong

Date: 24 Aug, 2013 14:14:09

Message: 2 of 3

"Larry Rose" <larryrose.rose843@gmail.com> wrote in message <kv8u3t$esp$1@newscl01ah.mathworks.com>...
> hey all,
> this here works:
> B = [1 2 3
> 1 3 4
> 2 2 2
> 3 4 5
> 3 3 3
> 3 5 9
> 4 8 9]
>
> [unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]
>
> But, if I change matrix B's left column to these large numbers I get error.
> so this below does not work:
> format long
> B = [20120101 2 3
> 20120101 3 4
> 20120102 2 2
> 20120103 4 5
> 20120103 3 3
> 20120103 5 9
> 20120104 8 9]
>
> [unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]
>
>
> Here is the error message:
>
> ??? Error using ==> horzcat
> CAT arguments dimensions are not consistent.
>
> Error in ==> accumarray_issue at 22
> [unique(B(:,1)),accumarray(B(:,1),B(:,2),[],@prod)]
>
>
> Thanks a lot,
> Larry

The error message is pretty clear: unless your B(:,1) fully covers integer from 1, 2 ..., to max(B(:,1)), you'll get different dimensions between accumarray and unique outputs. So you won't be able to concatenate them.

Bruno

Subject: accumarray issue (not working with large numbers?)

From: Steven_Lord

Date: 26 Aug, 2013 14:41:39

Message: 3 of 3



"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message
news:kvaf3h$4nl$1@newscl01ah.mathworks.com...
> "Larry Rose" <larryrose.rose843@gmail.com> wrote in message
> <kv8u3t$esp$1@newscl01ah.mathworks.com>...

*snip*

> The error message is pretty clear: unless your B(:,1) fully covers integer
> from 1, 2 ..., to max(B(:,1)), you'll get different dimensions between
> accumarray and unique outputs. So you won't be able to concatenate them.

As a concrete example of what Bruno said:

accumarray(2, 3, [], @prod) % returns [0; 3] since nothing's assigning a
value to the first element
unique(2) % returns 2

[2, [0; 3]] % errors since you can't concatenate horizontally something with
1 row and something with 2 rows.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us