Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!news2.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!newsfe05.iad.POSTED!7564ea0f!not-for-mail
From: Walter Roberson <roberson@hushmail.com>
Organization: Canada Eat The Cookie Foundation
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Number of changes in a value
References: <ghmadq$egh$1@fred.mathworks.com> <ghmcfe$gq8$1@fred.mathworks.com>
In-Reply-To: <ghmcfe$gq8$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 25
Message-ID: <y9z%k.777$Ir1.624@newsfe05.iad>
NNTP-Posting-Host: 24.79.146.116
X-Complaints-To: internet.abuse@sjrb.ca
X-Trace: newsfe05.iad 1228848862 24.79.146.116 (Tue, 09 Dec 2008 18:54:22 UTC)
NNTP-Posting-Date: Tue, 09 Dec 2008 18:54:22 UTC
Date: Tue, 09 Dec 2008 12:54:33 -0600
Xref: news.mathworks.com comp.soft-sys.matlab:505913


Roger Stafford wrote:
> "anoop Sivasankaran" <anooppgd@gmail.com> wrote in message <ghmadq$egh$1@fred.mathworks.com>...

>> Now I need to find number of changes. i.e I need to find how many changes from 1 to 2, 1 to 3,
>> 1 to 4, 2 to 1, 2 to 3 etc. 

> sum(diff(data)~=0)

Hmmm, my interpretation was that Anoop needs the counts for the cases individually, but
certainly that isn't clear.

Interesting, your formulation was the fastest of the several I tried
at about 0.15 seconds; several variants came in about 0.16 seconds, and
sum(data(1:end-1)~=data(2:end)) was about 0.31 seconds

The graycomatrix that I suggested in a posting above takes about 4 seconds
to produce the full 4 x 4 table.

And then there is:

[A,B] = meshgrid(1:4,1:4);
arrayfun(@(a,b) sum(foo(1:end-1)==a&foo(2:end)==b), A,B)
which takes about 6 seconds for the arrayfun

I couldn't seem to formulate the equivalent in bsxfun.