matlab data parsing help- pulling only certain characters
이전 댓글 표시
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
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
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)
카테고리
도움말 센터 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!