Clean solution to shrink matrices

9 ビュー (過去 30 日間)
Pappu Murthy
Pappu Murthy 2017 年 5 月 9 日
回答済み: Prema Gopalakrishnan 2019 年 7 月 23 日
I have pre-allocated a large Matrix X = (80000,8). for e.g zeros(80000,8); This I did for speed. After several operations I only filled say 1000 rows of the matrix and remaining are all zeros as I pre-allocated all elements to be zero to start with. Now I would like the shrink the matrix to smaller one by eliminating all the trivial rows in the end. What is the cleanest way of doing them?

採用された回答

Prema Gopalakrishnan
Prema Gopalakrishnan 2019 年 7 月 23 日
X = X(1:n,:);

その他の回答 (1 件)

John D'Errico
John D'Errico 2017 年 5 月 9 日
As long as you know how many rows are filled (call it n, here n is 1000), then just do
X = X(1:n,:);

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by