how to match two consecutive items

1 visualizzazione (ultimi 30 giorni)
Mekala balaji
Mekala balaji il 29 Mar 2018
Commentato: Mekala balaji il 13 Apr 2018
Hi,
I have below data:
Start
PAJ04
Type
Model
End
time
2018-01-2
Data aquire
Start
time
-
Date
2018-02-10
Start time
00:12:24
End
time
00:32:15
Acquired
time
01:15:26
Running sequence
AT09K00
I want catch Date, Start time, End time, acquired time, and running sequence
but some time end time occurs multiple time. I want to catch the first occurrence after the start time
Desired output
Date Start time End time Acquired time Running sequence
2018-02-10 00:12:24 00:32:15 01:15:26 AT09K00
alos How to string match two cosequtive rows for example: to catch "start time:
match first line is "Start", immediate row to be matched is "time", then it is Start time

Risposte (1)

Elias Gule
Elias Gule il 29 Mar 2018
Assuming that you have stored your text in a variable named "txt". The following code should do what you want.
txt = regexprep(txt,'\r?\n',' '); %%replace carriage return and newline character with whitespace
pattern = {'(Date\s*\d{4}-\d{2}-\d{2})',...
'(Start\s*time\s*(\d{2}:\d{2}:\d{2}))',...
'(End\s*time\s*(\d{2}:\d{2}:\d{2}))',...
'(Acquired\s*time\s*(\d{2}:\d{2}:\d{2}))',...
'(Running\s*sequence\s*\w+)'};
output = regexpi(txt,pattern,'match');
output = cellfun(@(x) regexp(x,'\s(?=\d)|(?<=sequence)\s+','split'),...
output,'uni',0);
headerline = char(join(cellfun(@(x) sprintf('%-20s',x{1}{1}),output,'uni',0)));
values = char(join(cellfun(@(x) sprintf('%-20s',x{1}{2}),output,'uni',0)));
output_txt = sprintf('%s\n%s',strtrim(headerline),strtrim(values))
  1 Commento
Mekala balaji
Mekala balaji il 13 Apr 2018
Error using regexpi Multiple strings and patterns given must have the same quantity.

Accedi per commentare.

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by