Reading a text file

2 visualizaciones (últimos 30 días)
Meisam
Meisam el 24 de Feb. de 2012
Hi Matlabers :D I have another question, I have a Txt file that is full of numbers and text, which are not created based on an easy rule. So i need Matlab to read the file, and extract some parts of it and some numbers related to this words, what shall i do? here is a part of the text, and i need Matlab to find (OnEventReached : 16, time = 4,03965837112068 ) in this text.
2012 Fri Feb 03 10:35:40.49 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] SelectMotionType Joint .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:40.221 0:172 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] DefineEvent 17 for target 3, location ToY352SB9301_20 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:40.221 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] RegisterToLocationReachedNotification .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:41.267 1:46 Infrastructure INFO start incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2395) 2012 Fri Feb 03 10:35:41.267 0:0 Infrastructure INFO finish incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2400) 2012 Fri Feb 03 10:35:47.439 6:172 Infrastructure INFO start incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2395) 2012 Fri Feb 03 10:35:47.470 0:31 Infrastructure INFO finish incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2400) 2012 Fri Feb 03 10:35:49.923 2:453 Infrastructure INFO start incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2395) 2012 Fri Feb 03 10:35:49.938 0:15 Infrastructure INFO finish incremental loading refresh .\grajtgraphicviewer\GraJtTuneGraphicViewer.cpp (2400) 2012 Fri Feb 03 10:35:50.563 0:625 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] OnEventReached : 16, time = 4,03965837112068 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:50.563 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] Call Delegate ToY352SB9301_10: SimulateNotifyProcessingTargetEndedStep2 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:50.563 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] Notify ProcessingTargetEnded ToY352SB9301_10 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:50.579 0:16 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] Call Delegate ToY352SB9301_10: SimulateNotifyMovingToTargetStartedStep2 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:50.579 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] Notify MovingToTargetStarted ToY352SB9301_20 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:50.579 0:0 ApiBaseToolsError ERROR APIFUNCGM_ATTR_NOT_FOUND StudyLevelRoboticParameter_OLP_SIM_OPTION_DISPLAY_BLANK_GUNS .\src\apiGetAttributes.cpp (246) 2012 Fri Feb 03 10:35:52.313 1:734 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] OnLocationReached : 4,35219989395141 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] # NotifyProcessingTargetEnded ToY352SB9301_20 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] RegisterToLocationReachedNotification (with Target Id : 3) .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] AddLocationReachedCallback SimulateNotifyProcessingTargetEndedStep2 (with Target Id : 3) .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] # NotifyMovingToTargetStarted ToY352SB9301_30 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] RegisterToLocationReachedNotification (with Target Id : 3) .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.313 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_20 : [DBG] AddLocationReachedCallback SimulateNotifyMovingToTargetStartedStep2 (with Target Id : 3) .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.329 0:16 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Notify ProcessingTargetStarted ToY352SB9301_30 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.329 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] move to loc ToY352SB9301_30 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.329 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] SetConfigControl ConfJ ON .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.360 0:31 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] SetConfigControl ConfL ON .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.407 0:47 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Set TCP Speed 2500 mm/s .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.438 0:31 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Set Orientation Speed 500 deg/s .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.469 0:31 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Set Flyby ZoneData z20 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.719 0:250 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Select FlyBy Mode True .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.766 0:47 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] SetMountedToolFrames .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.766 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] Set load for tooldata gun023fs2_35 .\RobEngCsBaseDelegator.cpp (1113) 2012 Fri Feb 03 10:35:52.766 0:0 ApiBaseToolsError ERROR ROBOTIC_CONTROLLER_SIM_ERROR r64_21_000[RRS]> Note at ToY352SB9301_30 : [DBG] SelectMotionType Linear .\RobEngCsBaseDelegator.cpp (1113)

Respuesta aceptada

Rocio saracho
Rocio saracho el 27 de Feb. de 2012
The following set of code should work (or give you an idea of one way of doing it):
% read from the text file into a cell array
s = textread('myfile.txt','%s');
% flatten from a cell array to a string
s = [s{:}];
% find out the index for the word "OnEventReached"
pos = (strfind(s,'OnEventReached'));
% extract from the string from OnEventReached to the end
% assuming it just happens once)
s = s(1,pos:end);
% dissect the string with textscan (assuming we are always
% looking for a
% string witht a similar format
% "OnEventReached:NUMBER,time=NUMBER,NUMBER"
result = textscan(s,'%[^:] %*c %f %*c %[time] %*c %f %*c %f',1)
  1 comentario
Meisam
Meisam el 28 de Feb. de 2012
Thanks Rocio. It is really a good hint.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by