How extract sub matrix without zeros from a big matrix
古いコメントを表示
Hello everybody ... I have a big matrix [N] as shown in Figure. I need to extract sub-matrix from [N]: [A],[B],[C],[D], [E] .... The end of each row can contain some zeros (red part). So I need to extract these sub-matrix. If [A] has the same number of columns of [E], I have to combine them in a unique matrix ([F]=[A];[E]). [N] does not contain zeros in the white part. Could you help me with this problem? Thank you very much for your time

2 件のコメント
KL
2017 年 11 月 3 日
what do you mean by big matrix? be specific? what's the size? How do you identify A,B,C,D and E within N? How are they distributed across N's rows?
gianluca scutiero
2017 年 11 月 3 日
採用された回答
その他の回答 (2 件)
Guillaume
2017 年 11 月 3 日
If I understood correctly:
%N: your big matrix
rowswithnozeros = cellfun(@(row) nonzeros(row).', num2cell(N, 2), 'UniformOutput', false);
rowlength = cellfun(@numel, rowswithnozeros);
[~, ~, subs] = unique(rowlength, 'stable'); %s'stable' optional
matriceswithnozeros = accumarray(subs, (1:numel(rowswithnozeros))', [], @(rows) {vertcat(rowswithnozeros{rows})});
3 件のコメント
gianluca scutiero
2017 年 11 月 3 日
Guillaume
2017 年 11 月 3 日
"But is there the possibility to join the rows generated with the same numbers of columns ?"
That's the whole purpose of the last three lines.
gianluca scutiero
2017 年 11 月 3 日
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
