Filter löschen
Filter löschen

Remove elements from string array

18 Ansichten (letzte 30 Tage)
anon
anon am 26 Nov. 2019
Beantwortet: Guillaume am 26 Nov. 2019
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 Kommentare
Guillaume
Guillaume am 26 Nov. 2019
What is the rule that dictates which elements should be removed from the string array?
anon
anon am 26 Nov. 2019
Create a new array that contains only integers. So after removing all non-integers the array would need to be turned into a numeric array e.g. [1,2,3,10]

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Guillaume
Guillaume am 26 Nov. 2019
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.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by