Remove 0 values from an array
5 ビュー (過去 30 日間)
古いコメントを表示
I've read in data from an Excel spreadsheet consiting of 7 rows and 3 columns.
In each colum there is a 0 value (column 1, row 7; column 2, row 2; column 3, row 4).
Is there a way to remove these values from the array (without modifying the initial data that is brought in from Excel)?
3 件のコメント
DGM
2022 年 3 月 9 日
編集済み: DGM
2022 年 3 月 9 日
Even if there is only one zero value per column, removing them and collapsing vertically will mean your data is misaligned in the region where values were removed.
For example:
% create a patterned array
A = (1:10)' + (10:10:30);
A([3 15 27]) = 0
% remove zeros and reshape
A = reshape(A(A~=0),[9 3])
% note the loss of alignment in the middle
all(range(mod(A,10),2)==0,2)
回答 (1 件)
Rik
2022 年 3 月 9 日
% create a patterned array
A = (1:10)' + (10:10:30);
A([3 15 27]) = 0;
row_has_zero = any( A==0 ,2)
A(row_has_zero,:)=[]
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!