i need to convert below batrix to another matrix

1 回表示 (過去 30 日間)
Nitin Sapre
Nitin Sapre 2019 年 11 月 8 日
コメント済み: Walter Roberson 2019 年 11 月 8 日
b=[308 -1 2 3 -1 2 -1;
-1 -1 2 1 0 1 0;
1 2 -1 -1 -1 -1 2;
0 0 1 -1 -1 2 -1];
to
b=[308 2 3 2 ;
2 1 0 1 0;
1 2 2;
0 0 1 2 ]
fill all ending elements with 0
b=[308 2 3 2 0 ;
2 1 0 1 0;
1 2 2 0 0;
0 0 1 2 0]
thanks
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 8 日
Is it correct that the rule is that each row should have all negative values removed, and then all rows should be padded out with 0 to the length of the longest remaining row ?

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

採用された回答

KSSV
KSSV 2019 年 11 月 8 日
b=[308 -1 2 3 -1 2 -1;
-1 -1 2 1 0 1 0;
1 2 -1 -1 -1 -1 2;
0 0 1 -1 -1 2 -1];
% Get positive count from each row
N = sum(b>0,2) ;
iwant = zeros(size(b,1),max(N)) ;
for i = 1:size(b,1)
bi = b(i,:) ;
iwant(i,1:N(i)) = bi(bi>0) ;
for
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 8 日
Should be b>=0 as row 2 shows an example of a 0 being preserved.

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

その他の回答 (1 件)

Nitin Sapre
Nitin Sapre 2019 年 11 月 8 日
Yes sir that's what I need

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by