Finding titles in a notepad file

Hello everyone,
I have a large notepad file and I want to be able to type in a fault and find that fault in the file and display the time that it occured for every one of those faults.
This is a segment of data from the file:
I want to be able to type in RADAR_FAULT and find all radar faults and display the time of each one in a column of data labeled "time"
10/13/2010 - 11:13:53.03456 - RADAR_FAULT
10/13/2010 - 11:13:53.78990 - COMPUTER_INITIALIZED
10/13/2010 - 11:13:54.43567 - SONAR_FAULT
10/13/2010 - 11:13:55.19587 - TEMPERATURE_MEASUREMENT
10/13/2010 - 11:13:56.09851 - TEMPERATURE_MEASUREMENT
The end result would be a column of data labeled time (for example)
Time: 10/13/2010 - 11:13:53 10/13/2010 - 11:15:23 10/13/2010 - 11:27:46 10/13/2010 - 12:02:49 etc.

 Respuesta aceptada

Oleg Komarov
Oleg Komarov el 18 de Jul. de 2011
Import with textscan and use strcmpi
fid = fopen('test.txt');
out = textscan(fid,'%27s - %s','Delimiter','','CollectOutput',1);
fid = fclose(fid);
out{1}(strcmpi('RADAR_FAULT',out{1}(:,2)),1);

7 comentarios

Fish
Fish el 21 de Jul. de 2011
I used this code for the exact data that I posted on the site but I was unable to get into the lab to actually test the code on teh actual text files. The code returned only a 1X1 cell.
I am going to post the exact data because apparently the data is slightly off from what i posted therefore rendering the code insufficient for the real data.
Here it is:
The top of the file (there are multiple ones of this type of text data) has 17 lines of text/numeric data telling how many of each type of error are in the file.
Then it says about 100 lines with the dates like so:
10/13/2010 - 11:13:53.034567 - error_name #### Description
The spaces in between the error_name and the #### and the Description are tab spaces (not space bared over)
Then it says a line of data about the time zone that the times are in
then it has
10/13/2010 - 11:13:53.03456 - RADAR_FAULT
line of data
line of data
line of data
10/13/2010 - 11:13:53.78990 - COMPUTER_INITIALIZED
10/13/2010 - 11:13:53.78990 - COMPUTER_DOWN
10/13/2010 - 11:13:53.78990 - COMPUTER_INITIALIZED
line of data
line of data
line of data
line of data
line of data
line of data
10/13/2010 - 11:13:54.43567 - SONAR_FAULT
10/13/2010 - 11:13:55.19587 - TEMPERATURE_MEASUREMENT
10/13/2010 - 11:13:56.09851 - TEMPERATURE_MEASUREMENT
line of data
line of data
The point is once the text file gets to the information where it displays the time of the RADAR_FAULT, it is not always set up the same way. The text lines are variable like shown above.
The end result should just be a column that lists the time of each RADAR_FAULT.
Fish
Fish el 21 de Jul. de 2011
After the line with the time and the error name the "lines of data" below it are spaced in two space bars. (I don't know why I wasn't able to type that when I was trying to explain this problem).
Fish
Fish el 21 de Jul. de 2011
After the line with the time and the error name the "lines of data" below it are spaced in two space bars. (I don't know why I wasn't able to type that when I was trying to explain this problem).
Fish
Fish el 21 de Jul. de 2011
After the line with the time and the error name the "lines of data" below it are spaced in two space bars. (I don't know why I wasn't able to type that when I was trying to explain this problem).
Fish
Fish el 21 de Jul. de 2011
sorry my computer froze
Oleg Komarov
Oleg Komarov el 21 de Jul. de 2011
So, what are you interested in? Only in the lines which begin with a date?
Fish
Fish el 21 de Jul. de 2011
yes and only those that have the error code: RADAR_FAULT next to them

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

el 18 de Jul. de 2011

Community Treasure Hunt

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

Start Hunting!

Translated by