help-octave
[Top][All Lists]
Advanced

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

Re: How to extract sequenced data from an array?


From: Ghostly
Subject: Re: How to extract sequenced data from an array?
Date: Fri, 31 Dec 2010 18:39:17 +0100

Thanks for your replies

I tried your code and it works fine. My problem with it, is that when I use my 
data (5 decimal point single column matrix) instead your random vector "a", I 
get this error:

repmat: with 3 arguments m and n must be scalar

pointing to:

if(isequal(a,resize([repmat(a(1:tmp),1,ntimes),a(tmp)],1,tam)))

Cheers

> function period=find_period(a)
> % We find every repetition of first element and discard itself
> % Any of those can be the period
> ind=find(a==a(1));
> ind(1)=[];
> [tam]=length(a);
> period=0;
> for tmp=ind
>   tmp=tmp-1;
>   % We must calculate how many times the period can fit there
>   ntimes=ceil(tam/tmp);
>   % And then we check if the resulting matrix is equal
>   if(isequal(a,resize([repmat(a(1:tmp),1,ntimes),a(tmp)],1,tam)))
>     period=tmp;
>     break;
>   endif
> endfor
> endfunction



reply via email to

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