reading whitespace in textscan
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi,
I have some data to read in fixed field format as date/time (ddmmyyyyHHMM) then 4 data fields, as per this example:
24 91987 530 0.8455 0.7200 -0.1255 -0.1255
30 919872345 0.8329 0.7500 -0.0829 -0.0829
1101987 0 0 0.8687 0.8000 -0.0687 -0.0687
My code is:
resarr=textscan(fidres,'%2f%2f%4f%2f%2f%10.4f%10.4f%10.4f10.4f','whitespace','','delimiter','/n');
res= [datenum([resarr{:,3},resarr{:,2},resarr{:,1},resarr{:,4},resarr{:,5},zeros(size(resarr{:,1},1),1)]),resarr{:,6},resarr{:,7},resarr{:,8},resarr{:,9}];
I'd like to read the data and convert the date to datenum. But am having a lot of trouble with the whitespaces.
eg the first line gives 24,91,987,53,0,0.8455,0.7200,-0.1255,-0.1255
instead of 24,9,1987,5,30,0.8455,0.7200,-0.1255,-0.1255
How should I change the textscan?
댓글 수: 0
답변 (1개)
Hugo
2013년 6월 12일
I can only think of two options:
1) Add spaces separating the fields in the data, i.e. instead of ddmmyyyyHHMM, modify the data so that you have dd mm yyyy HH MM. That should be easy.
2) The other way is to scan for text
resarr=textscan(fidres,'%2s%2s%4s%2s%2s%10.4f%10.4f%10.4f10.4f','whitespace','','delimiter','/n');
and then convert the text to numbers using, for example, str2double or str2num
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!