필터 지우기
필터 지우기

matlab data parsing help- pulling only certain characters

조회 수: 1 (최근 30일)
Michael
Michael 2011년 4월 14일
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!

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by