Extracting time from a string
이전 댓글 표시
Hi could i extract the time from this line, which is saved as a text
90 83 3010 Kobe Soto Lewisville 18:19.9 5:52/M 9
the desired extraction is : 18:19.9,
now this will have to repeat for other 300 similar lines like the one above.
댓글 수: 1
Walter Roberson
2020년 5월 27일
What is known to be consistent? Will it always be in the 7th field? Will it always be in the 3rd last field? Is it guaranteed that there will be a decimal point in the time? Will the time have leading 0 for before 12:00 ?
답변 (1개)
Cris LaPierre
2020년 5월 28일
편집: Cris LaPierre
2020년 5월 28일
I used to be very involved in XC and track and field, so of course I had to help you out. Here you go:
% Scrape the data from the webpage
url = 'https://tx.milesplit.com/meets/242182/results/474095/raw#.Xs8w-8ApCMo';
code = webread(url);
str = extractHTMLText(code);
% Read in and format the data
varNames = ["Place" "AdjPlace" "Bib No" "Name" "Team" "Time" "Pace" "YR"];
data = textscan(str(6:end),'%f %q %f %q %C %{mm:ss.S}T %{mm:ss}T %*q %f',...
'Delimiter',{'\t','/'},...
"EndOfLine",'\n',...
"HeaderLines",5,...
"TextType",'string');
% Place the results in a table
results = cell2table(data);
results = varfun(@(x) x{:},results);
results.Properties.VariableNames = varNames
If you are new to tables, take a minute to go through this doc page. You can also see an introduction to accessing data in a table in this video from the Exploratory Data Analysis with MATLAB course on Coursera.
In short, you use dot notation to indicate which table variable to use. For example
results.Time(90)
ans =
18:19.9
If you want the entire row, use the (row, column) syntax instead:
results(90,:)
ans =
Place AdjPlace Bib No Name Team Time Pace YR
_____ ________ ______ ___________ __________ _______ _____ __
90 "83" 3010 "Kobe Soto" Lewisville 18:19.9 05:52 9
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!