I'm interested in finding the quickest way of grouping the rows of a large matrix in sub-groups based on the position of non-zero elements in the first column and then repeating them number of times based on the value of the non-zero element. The final output matrix is the repeated (or expanded) matrix. An example is shown as an image below: The first row, first element is always non-zero. one non-zero element in the first column can be followed by another non-zero element without being followed by zero. If a non-zero element is followed by zeros it is added to the group as shown in the figure. Length of a group is from one non-zero element until before the next non-zero element. Here is another example for more clarity.
Thank you in advance for your help.