matlab data parsing help- pulling only certain characters

1 次查看(过去 30 天)
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

回答(3 个)

Matt Tearle
Matt Tearle 2011-4-14
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=',''))

Matt Fig
Matt Fig 2011-4-14
Also,
Rs = cellfun(@(x) x(21:35),quat1,'Un',0);
To convert to doubles, use:
Rd = cellfun(@(x) str2double(x(21:35)),quat1)

Michael
Michael 2011-4-14
wow.. thank you both! very helpful!

标签

Community Treasure Hunt

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

Start Hunting!

Translated by