# Index chunks of cell to make block diagonal matrix.

2 views (last 30 days)
Mohammed Kagalwala on 5 Dec 2019
Hi,
I currently have a cell structure where each element is a 6x6 matrix.
I have an array l = [0 1 2 0 4], based on this array I have to extract chunks of the cell structure and develop a block diagonal matrix. The mapping from l to the cell chunks is as follows,
There are 2 zeros in l in position 1 and 4. These are the columns I want. The rows I want are 1:3, (in column 1) and 4:5 (in column 4). The 1:3 is obtained from the fact that next 0 in l after that in position 1 appears in position 4, so the range is 1:3. Similarily 4:5 is obtained from the fact that there is no 0 after the one in position 4, so you choose rows 4:end.
Thus I ultimately want A = diag(T{1,1},T{2,1},T{3,1},T{4,4},T{5,4})
I can get the right columns by simply creating a logical index from l == 0, however I'm stuck on obtaining the rows, without a for loop implementation.
Note: The vector l provided is only an example, the no. of zeros is not fixed.
I tried my best to explain my logic. I really hope someone can help.