So i have a table of numbers read in using fread from a .dat file:
0 0 3.51563 50 35.1563
0.094 10 3.47656 50 34.7656
Including some decimals and some integers, I've tried using:
numdata=regexp(data,'(-)*(\d+.)*(\d+)','match');
to get each of these numbers into an individual element of array numdata but for some reason regexp reads in the whole line of numbers into one element rather than each one individually. Thanks for any help
You won't be able to get that from regexp. You will be able to get numdata{1} = '0', numdata{3} = '3.51563' and so on, and you will be able to use str2double() to convert the values to numeric. However, if you were going to use str2double() to convert the values to numeric then you might as well let str2double() do almost all the pattern recognition, just using regexp() to 'split' on whitespace (because str2double will only process one number per string.)
The dot matches everything. You need \. to match a period.
numdata = regexp(data, '-?\d+(\.\d+)?', 'match');
This assumes that if the decimal point is present then it is always followed by at least one digit, and it assumes that there is always at least one digit before the decimal point. In particular,
17.
and
.3579
are examples of numeric formats that the expression would not match.
The expression always will not match numbers in exponential format.
Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.
Translated by
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.