[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

accumarray, non canonical indices, tabulation

From: forkandwait
Subject: accumarray, non canonical indices, tabulation
Date: Wed, 8 Sep 2010 18:08:47 +0000 (UTC)
User-agent: Loom/3.14 (

Hi all,

While I know how to use unique with accumarray to compensate for indices other
than 1:N, and can write a function to do it automatically, I was wondering if
there were a canonical way to deal with this problem.

For a simple example, consider FIPS codes for counties -- they generally start
at 1, then go up by 2 until the counties are exhausted alphabetically.  So
"Adams" would be 1, then "Asotin" would be 3, etc.

Here is a sample 1-d table of county data.

ctyi = (1:2:77)';
data = rand(39,1);
table = accumarray(ctyi, data, [], [], NaN);

The last command gives a matrix with nan's wherever there is a gap in the series
for ctyi.  I don't want that; I don't want those columns at all.

How do other people address this problem?  I will probably write
"celldata=accumarray_()" which uses unique and returns a cell array such that a
table with row and column headings can be reconstructed with mat2cell(), but if
there is a better / more common way I would like to know about it.  (or if
somebody has already invented that wheel...)

    celltable=accumarray_(ctyi, data);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]