Extracting lower triangle excluding the main diagonal elements to a string

1 回表示 (過去 30 日間)
RR RR
RR RR 2019 年 11 月 17 日
回答済み: Guillaume 2019 年 11 月 17 日
Hi all,
How to extract the lower triangle part of a matrix "excluding" the main diagonal elements, and put it as a string that has "\n" at the end of ech row?
For example:
A=[1 2 3 4; 0 6 7 8; 9 10 11 12; 13 14 15 16];
The output should be this:
B="0 \n 9 10 \n 13 14 15";

採用された回答

Guillaume
Guillaume 2019 年 11 月 17 日
B = strjoin(arrayfun(@(row) strjoin(compose('%d', A(row, 1:row-1)), ' '), 2:size(A, 1), 'UniformOutput', false), '\n')
is one way. Or use an explicit loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by