MATLAB: How to get the maximum numbers of every “increasing pattern” in each row in a matrix

arrayconsecutiveincreasing numbermatrixmaximum

Here is a matrix A consisting of "increasing patterns".
A=[1,2,3,1,2,3,4,1,2,1,2,3,4,1,1;1,2,1,1,2,3,1,2,3,4,1,2,3,4,5]
In each row of matrix A, all "increasing patterns" begin with 1.
Visually, all "patterns" are underlined separately below. The largest numbers in all "patterns" are in bold.
A =
1 2 3 1 2 3 4 1 2 1 2 3 4 1 1
1 2 1 1 2 3 1 2 3 4 1 2 3 4 5
How do I get B? This is, get the maximum numbers of all "patterns" in each row.
B=3 4 2 4 1 1
2 1 3 4 5 0
% use zero to fuilfill matrix B to make dimensions of each row consistent

Best Answer

>> A = [1,2,3,1,2,3,4,1,2,1,2,3,4,1,1;1,2,1,1,2,3,1,2,3,4,1,2,3,4,5]
A =
1 2 3 1 2 3 4 1 2 1 2 3 4 1 1
1 2 1 1 2 3 1 2 3 4 1 2 3 4 5
>> X = diff(A,1,2)~=1;
>> X(:,end+1) = true;
>> B = A.*X
B =
0 0 3 0 0 0 4 0 2 0 0 0 4 1 1
0 2 1 0 0 3 0 0 0 4 0 0 0 0 5