Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Finding and Replacing Consecutive Numbers in an Array
Date: Fri, 1 Apr 2011 07:12:05 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 59
Message-ID: <in3ts5$j07$1@fred.mathworks.com>
References: <imvasa$gbb$1@fred.mathworks.com> <in3qhn$rv3$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1301641925 19463 172.30.248.47 (1 Apr 2011 07:12:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 1 Apr 2011 07:12:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2488098
Xref: news.mathworks.com comp.soft-sys.matlab:719458

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <in3qhn$rv3$1@fred.mathworks.com>...
> You might try this code using my SplitVec function on FEX: 
> 
> % http://www.mathworks.com/matlabcentral/fileexchange/?term=SplitVec
> X = [1 1 1 1 1 0 0 3 3 3 3 3 2 2 2 1 1]
> 
> [lgt v int] = SplitVec(X, [], 'length', 'firstelem', 'bracket'); % FEX
> Y = zeros(size(X));
> b = lgt >= 5;
> Y(int(b,1)) = diff([0 v(b)]);
> Y = cumsum(Y)
> 
> % Bruno


Hi Bruno,

Thanks for that. I was intrigued by your SplitVec function yesterday but couldn't figure out what to do with it. That works great for the test matrix but I'm getting the following error when i try to apply it to my code:

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

Error in ==> gazeplot at 36
a(int(b,1)) = diff([0 v(b)]);


My code:
x=load('C:\Logs\Prepared Data\world_data.txt'); % Loads text log containing 3 columns

%The following section creates one array for each of the columns from the loaded log file
X=(x(:,1)); 
Y=x(:,2);
C=(x(:,3)); 

%Shift timing column (X) to give timing in seconds starting at 0secs
Xmax = max(X);
Xmin = min(X);
T = Xmax - Xmin;
Z = (X) - Xmin;


[r] = find(Y<1);  % Find all zero elements in Y column
Y(r)= C(r);        % Replace all zero elements with corresponding element from C column

[lgt v int] = SplitVec(Y, [], 'length', 'firstelem', 'bracket'); % FEX
a = zeros(size(Y));
b = lgt >= 5;
a(int(b,1)) = diff([0 v(b)]);      %This is the line which is giving me the error.
a = cumsum(a)

Y=a;
A=Y;


I can't see what's causing the problem, it works fine for smaller arrays that I've tried, and I know that your SplitVec function works fine on this array as I tried it yesterday.

Regards,

Ern