Azzera filtri
Azzera filtri

subtracting a number from string

1 visualizzazione (ultimi 30 giorni)
moaad abd allatif
moaad abd allatif il 21 Mag 2019
Commentato: Star Strider il 21 Mag 2019
how i can subtract a number from string ?
for example :
subject1_EO - i want to extract only number one..
  1 Commento
KSSV
KSSV il 21 Mag 2019
how i can subtract a number from string ? how?

Accedi per commentare.

Risposte (2)

Star Strider
Star Strider il 21 Mag 2019
One approach:
str = 'subject1_EO';
nrc = regexp(str, '\d+', 'match')
nr = str2double(nrc{:})
producing:
nrc =
1×1 cell array
{'1'}
nr =
1
  2 Commenti
Stephen23
Stephen23 il 21 Mag 2019
+1 a cunning use of a comma-separated list combined with the demand-driven output of nested functions. Explicit indexing is clearer though:
nr = str2double(nrc{1})
Star Strider
Star Strider il 21 Mag 2019
Thank you!

Accedi per commentare.


Stephen23
Stephen23 il 21 Mag 2019
Modificato: Stephen23 il 21 Mag 2019
The most efficient solution by far (and simple too!):
>> str = 'subject1_EO';
>> val = sscanf(str,'subject%f')
val = 1

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by