matlab data parsing help- pulling only certain characters
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have a code where i parse certain information from a text file using textscan, and i have it read it out into a column of a cell array as the following:
quat1 =
''END_QUATERNION01'='-0.566692110E-01''
''END_QUATERNION01'='-0.456692110E-01''
''END_QUATERNION01'='-0.261692110E-02''
''END_QUATERNION01'='-0.736592110E-02''
however i am only interested in keeping the actual values without all the characters and letters (-0.566692110E-01). i know how to do it for the first row.. you just do: quat1{1}(21:35), but how can i do this for the entire column without having to manually filter each row (because there could be about 100 rows in the actual code i am working on.
So just a recap, i need the list given above saved as the following:
quat1_new =
-0.566692110E-01
-0.456692110E-01
-0.261692110E-02
-0.736592110E-02
any help would be great! thanks
0 commentaires
Réponses (3)
Matt Tearle
le 14 Avr 2011
You could use regexprep, but you could also modify your textscan format specifier to "notice" but not read these in the first place.
quat1 = regexprep(quat1,'''','')
quat1_new = str2double(regexprep(quat1,'END_QUATERNION01=',''))
0 commentaires
Matt Fig
le 14 Avr 2011
Also,
Rs = cellfun(@(x) x(21:35),quat1,'Un',0);
To convert to doubles, use:
Rd = cellfun(@(x) str2double(x(21:35)),quat1)
0 commentaires
Voir également
Catégories
En savoir plus sur Text Files dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!