Remove elements from string array
18 ビュー (過去 30 日間)
古いコメントを表示
What is the simpest way to remove string elements from an array? e.g. arr = [1, 2, 3, "x", "y", 10] would turn into [1,2,3,10]
4 件のコメント
Guillaume
2019 年 11 月 26 日
What is the rule that dictates which elements should be removed from the string array?
回答 (1 件)
Guillaume
2019 年 11 月 26 日
One possible way:
numericarray = double(yourstringarray); %convert string array to numeric. Text that can't be converted to numeric will end up as NaN.
numericarray = numericarray(mod(numericarray, 1) == 0); %only keep numbers that are integers. Will also remove NaNs.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!