Found the answer. Thanks

Found the answer. Thanks

1 件のコメント

James Tursa
James Tursa 2016 年 10 月 26 日
編集済み: James Tursa 2016 年 10 月 26 日
Please post a short example for us so we know what exactly you are trying to do. E.g., post a small example input matrix and then post the result(s) you would be expecting. Note that trying to name variables x1, x2, etc in a loop fashion is not a good idea.

サインインしてコメントする。

回答 (1 件)

James Tursa
James Tursa 2016 年 10 月 26 日

0 投票

Do you mean like this?
[rows cols] = size(a);
nDiags = rows + cols - 1;
b=fliplr(a);
x = zeros(min(rows,cols),nDiags);
for i=1:nDiags
d = diag(b,cols-i);
x(1:numel(d),i)=d;
end
Produces:
>> a
a =
1 2 3 4 5
12 -4 9 11 83
2 4 6 8 24
64 0 21 33 11
104 63 16 72 76
>> x
x =
1 2 3 4 5 83 24 11 76
0 12 -4 9 11 8 33 72 0
0 0 2 4 6 21 16 0 0
0 0 0 64 0 63 0 0 0
0 0 0 0 104 0 0 0 0

1 件のコメント

James Tursa
James Tursa 2016 年 10 月 26 日
OK, how about this?
[rows cols] = size(a);
nDiags = rows + cols - 1;
b=fliplr(a);
c = cell(nDiags,1);
for i=1:nDiags
c{i} = diag(b,cols-i);
end
x = vertcat(c{:})';

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

タグ

タグが未入力です。

質問済み:

2016 年 10 月 26 日

編集済み:

2017 年 6 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by