How extract sub matrix without zeros from a big matrix
Afficher commentaires plus anciens
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 commentaires
KL
le 3 Nov 2017
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
le 3 Nov 2017
Réponse acceptée
Plus de réponses (2)
Guillaume
le 3 Nov 2017
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 commentaires
gianluca scutiero
le 3 Nov 2017
Guillaume
le 3 Nov 2017
"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
le 3 Nov 2017
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
