Index chunks of cell to make block diagonal matrix.
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I currently have a cell structure where each element is a 6x6 matrix.
![Capture1.PNG](https://www.mathworks.com/matlabcentral/answers/uploaded_files/253036/Capture1.png)
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.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!