Extract upper diagonal half in a large cell array and replace rest with NaN

Hello,
I have a very large cell array and want to select upper diagonal from it and replace the rest with NaNs. For example, if I have a 5x5 cell array, I'd like to get a result similar to;
1,1 1,2 1,3 1,4 1,5
2,1 2,2 2,3 2,4 NaN
3,1 3,2 3,3 NaN NaN
4,1 4,2 NaN NaN NaN
5,1 NaN NaN NaN NaN

 採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 3 日
A=[1 2 3 4; 5 6 7 8; 9 10 11 12;13 14 15 16]
ii=ones(size(A))
idx=rot90(tril(rot90(ii)),-1);
A(~idx)=nan

4 件のコメント

SMA
SMA 2016 年 4 月 3 日
編集済み: SMA 2016 年 4 月 3 日
tril and triu does not work on cell arrays, otherwise this would have been simple. I have a very large cell array with each cell containing numeric arrays of different sizes.
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 3 日
use cell2mat
or without cell2mat
A={1 2 3 4; 5 6 7 8; 9 10 11 12;13 14 15 16}
ii=ones(size(A))
idx=rot90(tril(rot90(ii)),-1);
A(~idx)={nan}
SMA
SMA 2016 年 4 月 3 日
Thank you, that is what I was looking for without loops.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeOperating on Diagonal Matrices についてさらに検索

質問済み:

SMA
2016 年 4 月 3 日

コメント済み:

SMA
2016 年 4 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by