フィルターのクリア

Delete rows in a string array, if they just contain zeros

3 ビュー (過去 30 日間)
Tatjana Mü
Tatjana Mü 2022 年 6 月 23 日
回答済み: Star Strider 2022 年 6 月 23 日
Good Morning,
I have a string array (Mineralien_RL): The first column are text and the following are numbers.
I want to delete all the rows which just contains zeros (Like the one here in line 40).
I tried it this way:
Mineralien_RL(:,all(Mineralien_RL(:,2:end) == "0"))=[];
But it deletes nothing.
I appreciate any help :-)

回答 (2 件)

KSSV
KSSV 2022 年 6 月 23 日
I hope, your data is in a file.
T = readtable(myfile) ;
T(T.(2)==0,:) = [] ;
  2 件のコメント
Tatjana Mü
Tatjana Mü 2022 年 6 月 23 日
Sadly not. Its the end of a calculation. I want to delete the zero rows, so that I dont export files with over 5000 rows.
KSSV
KSSV 2022 年 6 月 23 日
How is your data? What class it is? Attach your data into a matfile.

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


Star Strider
Star Strider 2022 年 6 月 23 日
It would help to have the data you are working with.
With respect to troubleshooting —
First, see what the logical statement itself produces:
Lv = all(Mineralien_RL(:,2:end) == "0")
truevals = nnz(Lv)
then experiment, for example with variations of it:
Lv = all(Mineralien_RL(:,2:end) == 0)
truevals = nnz(Lv)
When you get the logic working, rather than deleting the rows you do not want, retain only the rows you want:
Mineralien_RL = Mineralien_RL(~Lv,:);
That is likely easier (at least it has been in my experience).
.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by