Running On matrix by diagonals

1 回表示 (過去 30 日間)
Harel Harel Shattenstein
Harel Harel Shattenstein 2018 年 7 月 8 日
編集済み: Guillaume 2018 年 7 月 8 日
I am looking for an algorithm that can collect the elements of a matrix in the following way
It can be a non square matrix too
So the answer would be [a41,a42,a31,a43,a32,a21,a44,...]

回答 (1 件)

Guillaume
Guillaume 2018 年 7 月 8 日
編集済み: Guillaume 2018 年 7 月 8 日
One option:
[rows, cols] = size(A);
indices = (1:cols+rows)*rows - (0:rows-1)'*(rows+1);
indices = indices(indices > 0 & indices <= numel(A));
A(indices)
Require R2016b or later for the implicit expansion of the subtraction

カテゴリ

Help Center および File ExchangeOperating on Diagonal Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by