matlab data parsing help- pulling only certain characters
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Matt Tearle
el 14 de Abr. de 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 comentarios
Matt Fig
el 14 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!