Hello all,
I have a matrix that contains two column. Column A is the time and column B is the value belonging to that time. Now, column B contains zero and nonzero elements. What I need to do is count all the zeros and nonzeros. So I choose for a logical that returns true if it is nonzero and false if it is zero. I need to count the amount of consecutive nonzero elements because this corresponds to the duration. I used the following code to do this:
CntsCheckDataD1 = CheckDataD1(:,2); CheckDataD1log = CntsCheckDataD1 ~= 0; CheckDataD1log = CheckDataD1log'; if (CheckDataD1log(1,1) == 0) == 1 CheckDataD1log = diff([0 find(diff(CheckDataD1log)) numel(CheckDataD1log)]); CheckDataD1log = CheckDataD1log'; onesCheckDataD1log = CheckDataD1log(2:2:end, :); else CheckDataD1log = diff([0 find(diff(CheckDataD1log)) numel(CheckDataD1log)]); CheckDataD1log = CheckDataD1log'; onesCheckDataD1log = CheckDataD1log(1:2:end, :)end
This returns all amount of ones in the matrix. I need to check where the first amount of consecutive ones is more than (for example) 15 and return the corresponding time from the CheckDataD1 matrix. Finding this value in the onesCheckDataD1log is easy but I do not know how I can find the corresponding time belonging to that value in the CheckDataD1 matrix..
Please help!
Best Answer