Assume input matrix I as follows:
I = [100 56 1100 54 1100 65 1101 5 0101 10 1101 15 1101 20 0101 30 1101 20 1101 50 1198 30 0198 20 1203 10 0203 5 1203 60 1203 20 1203 15 144 70 044 65 144 45 144 50 044 35 144 35 144 50 044 70 144 75 144 65 1];
I want to create 3 matrix based on the I matrix:
Matrix A:
Based on the unique ID in first column of matrix A, I want to generate numbers if ID is same then corresponding cell get same number and if the ID changed, the corresponding ID reset numbers. Also, if in the same ID number, from the third column in matrix I, there was an interrupt with value 0, then number reset and continue (see the figure below).
Matrix B:
Based on the out put of matrix A, I want to count how many number generated for every ID (and if there was an interrupt with 0). See the figure below.
Matrix C:
Based on the out put of matrix A, I want to sum up the corresponding cells from second column in matrix I. See the figure below.
A = [100 1100 1100 1101 1101 1101 1101 2101 2101 2101 2198 1198 1203 1203 1203 1203 1203 144 144 144 144 244 244 244 344 344 344 3];B = [100 3101 3101 4198 2203 544 344 344 4];C = [100 175101 30101 120198 50203 11044 18044 12044 260];
Best Answer