Path: news.mathworks.com!not-for-mail
From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Check if two shifted matrices are equal
Date: Fri, 7 Nov 2008 00:59:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 25
Message-ID: <gf03sm$p1f$1@fred.mathworks.com>
References: <gevia6$2hk$1@fred.mathworks.com>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226019542 25647 172.30.248.38 (7 Nov 2008 00:59:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 7 Nov 2008 00:59:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: news.mathworks.com comp.soft-sys.matlab:499420

"Colin " <colinzhe@gmail.com> wrote in message <gevia6$2hk$1@fred.mathworks.com>...

> 
> Perhaps there is a faster/easier way to accomplish this?
> 

a=[7   0   3   0   1   8   7   3  10   0];
b=[3   0   1   8   7   3  10   0   7   0];

% Engine
shift=findstr(b,[a a])-1

% Check
n = length(a);

if isempty(shift)
  fprintf('cannot match after circular shift')
else
  shift = shift(1);
  shiftedidx = mod((1:n)+shift-1,length(a))+1;
  isequal(b, a(shiftedidx ))
end
 
% Bruno