How to remove rows of empty strings?
52 ビュー (過去 30 日間)
古いコメントを表示
I have a string array which I have preallocated as follows:
BusName = strings(MaxB,NumBVF,1);
After reading in the data, my string array has many empty rows at the end.
So my question is: How do I remove all rows that consist entirely of blank strings ("")?
Here is what I've come up with so far:
BusName(strcmp(BusName(:,2),""),:) = [];
Unfortunately, it is removing rows that it shouldn't be (rows that have "" but also data).
Any suggestions (and explanation) will be greatly appreciated!
3 件のコメント
the cyclist
2019 年 10 月 30 日
編集済み: the cyclist
2019 年 10 月 30 日
Your upload worked! (And my solution works on your input.)
回答 (2 件)
the cyclist
2019 年 10 月 30 日
編集済み: the cyclist
2019 年 10 月 30 日
I'm having trouble following the logic in the command you posted, because you seem to be checking only the second column of Busname.
But I'm pretty sure you'll want to use the all command to get the rows where all the elements are blank.
I think it would be something like
BusName(all(strcmp(BusName,""),2),:) = [];
Walter Roberson
2019 年 10 月 30 日
編集済み: the cyclist
2019 年 10 月 30 日
BusName = rmmissing(BusName, 'MinNumMissing', size(BusName,2));
2 件のコメント
the cyclist
2019 年 10 月 30 日
Yeah, does not work on your string array.
(Walter, my edit of your answer was just to fix up 'MinMissing' to 'MinNumMissing').
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!