Good evening. For some time now I've been puzzling trying to figure out, as a basic matlab user, how to solve this problem: I have a column vector, A, of N elements, which are to be classified into two groups X and Z depending on whether the element satisfies a certain condition. Furthermore, each series of M consecutive elements that satisfies the condition must be grouped into a vector to be named progressively (for example, the first series of M consecutive elements that satisfies the condition of belonging to X, must be grouped into a vector X1 and so on). for example, once the elements that satisfy one or the other condition have been identified, I will find myself in a situation like A = (X, X, X, Z, X, Z, Z, Z, X, X, X); I must now group the series of at least 2 consecutive elements X into vectors Xi and into vectors Zi the series of at least 2 consecutive elements Z and, if there are isolated elements, group them in the vector that grouped the elements preceding it. in the example case, the result to be obtained would be the following:
X1 = (X, X, X, Z, X): the first 3 consecutive elements that satisfy the condition X, the isolated element that satisfies the condition Z and the element that satisfies condition X;
Z1 = (Z, Z, Z);
X2 = (X, X, X)
I have made many attempts (especially with for and if loops), but I have not been able to reach the goal. sure that someone will be pleased to deal with this question, I thank in advance anyone who can give me any advice on the matter.