Splitting up Numerical Text Data
이전 댓글 표시
I am using the webread function to obtain numerical text data from a webpage. Each row of data represents a different weather element while each column represents the forecast time. I have had success spliting up the numerical data from rows like TMP, DPT, and WSP (Temperature, Dew point, and Wind Speed) where the numbers usually only have two digits. However, when rows like TMP, SKY, VIS (Temperature, Sky Cover, Visiblity) have three digits, the text may appear: '89 93 96 9910010010098 96 94 90' and using str2num will output 89 93 96 9910010010098 96 94 90 when I want it to read 89 93 96 99 100 100 100 98 96 94 90 so I can plot the values. I've been using str2num for two digit numbers and it works great. Given that the string of numerical text can change for a different forecast time period and location, how can I write a section of code that splits up this data?
댓글 수: 4
Cris LaPierre
2020년 10월 26일
The issue here appears to be there is no clear delimiter between your numbers. Even though this data appears to be fixed width, the format changes. With it not being consistant, there is no simple fix I'm aware of.
Are you positive you copied the data correctly? Is there any chance it should be this?
'89 93 96 99100100100 98 96 94 90'
Mathieu NOE
2020년 10월 26일
hello
can you share some text data with your different data length
tx
Dalton Van Stratten
2020년 10월 26일
Cris LaPierre
2020년 10월 27일
편집: Cris LaPierre
2020년 10월 27일
Yes, that does change things. It means the data is fixed width, which makes it possible to separate. I therefore believe it is actually ' 89 93 96 99100100100 98 96 94 90'.
Answer below.
답변 (1개)
t = ' 89 93 96 99100100100 98 96 94 90';
T = textscan(t,'%3s','Whitespace','');
T = str2double(T{:})
댓글 수: 2
J. Alex Lee
2020년 10월 27일
is that any better than
T = cell2mat(textscan(t,'%3f','Whitespace',''));
?
I had tried %f, but for me, it wasn't capturing the numbers correctly.
t = ' 89 93 96 99100100100 98 96 94 90';
T = cell2mat(textscan(t,'%3f','Whitespace',''))
카테고리
도움말 센터 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
