To get the time value from a large array

I have a text file-
19,TRIP_BKR1,,,0
20,TRIP_BKR2,,,0
21,Trip 3Ph PHS,,,0
60.000000
1
1200.0000,749
16/07/2009,16:09:53.729166
16/07/2009,16:09:53.829775
ASCII
1
I want to fetch the time data in 3rd and 4th last rows of the above code and store it in a variable. I was using the following function to get it done-
trigger_time = strread(char(cfg_info_ar{1,8}(2)));
start_time = strread(char(cfg_info_ar{1,7}(2)));
Where cfg_info_ar is the file which has all the elements of the array
I was getting only 16 as both trigger_time and start_time. Can you help me out with getting the exact value of the time i,e. 16:09:53.829775 or just 53.829775? Thanks.

3 comentarios

Image Analyst
Image Analyst el 19 de Jul. de 2015
How large is it? How many gigabytes? You might have to use memmapfile() if it's really big.
Jan
Jan el 19 de Jul. de 2015
How can "cfg_info_ar" be "the file", when it is obviously a cell string? How did you obtain this variable? What is it's contents? What is the purpose of the (2)? How do you exclude the lines, which do not contain the lines? What is the exact definition of the pattern for the data?
strread is deprecated for many years now. So better use textread.
Mohit Sharma
Mohit Sharma el 19 de Jul. de 2015
Editada: per isakson el 19 de Jul. de 2015
Jan,
Yes cfg_info_ar is a cell string. I used the below method to obtain this cell string-
cfg_file = fopen(**file name and path**);
config = textscan(cfg_file, '%s', 'delimiter', '\n');
cfg_info_ar = cell(size(config));
cfg file is a configuration file of COMTRADE standard. So it has the information of all the channels(digital and analog). It also has information of the point in time when the fault is initiated (trigger_time). I just want to get that in a variable. The time data is in the format- 16:09:53.829775 (GPS time). I want to have only 53.829775. (2) denotes the second column as you can see first column has date and the second column has time in 3rd and 4th last rows.

Iniciar sesión para comentar.

Respuestas (2)

Image Analyst
Image Analyst el 19 de Jul. de 2015

0 votos

Have you seen COMTRADE Reader: http://www.mathworks.com/matlabcentral/fileexchange/15619-comtrade-reader? Does it do what you want?

2 comentarios

Mohit Sharma
Mohit Sharma el 19 de Jul. de 2015
It helps only with reading a COMTRADE file. I have to derive various quantities like harmonic distortion, sequence components after reading the file.
Image Analyst
Image Analyst el 20 de Jul. de 2015
You said that with how you read it, you got only 16 instead of 16:09:53.829775 so I figured it was a reader problem. Once it's read in properly of course you can do anything you want with the numbers but it sounds like you don't have the numbers read in properly yet.

Iniciar sesión para comentar.

per isakson
per isakson el 19 de Jul. de 2015
Editada: per isakson el 20 de Jul. de 2015
  • Why is the word "large" in the title? How large is the file?
  • These two dates are they the only ones in the file?
For a start try:
>> cssm
cac =
'53.729166' '53.829775'
num =
53.729165999999999 53.829774999999998
>>
where cssm.m is
function cssm
str = fileread( 'cssm.txt' );
cac = regexp( str, '(?<=\d{2}/\d{2}/\d{4},\d{2}:\d{2}:)\d{2}\.\d+', 'match' );
num = str2double( cac );
format long
cac
num
end
and cssm.txt consists of the sample you provided in the question
&nbsp
Triggered by the comments:
>> [ t1, t2 ] = cssm( 'c:\m\cssm\cssm.txt' )
t1 =
53.7292
t2 =
53.8298
where
function [ t1, t2 ] = cssm( filespec )
str = fileread( filespec );
cac = regexp( str, '(?<=\s\d{2}/\d{2}/\d{4},\d{2}:\d{2}:)\d{2}\.\d+\s', 'match' );
t1 = str2double( cac(1) );
t2 = str2double( cac(2) );
end

8 comentarios

Mohit Sharma
Mohit Sharma el 19 de Jul. de 2015
Yes, it has only these two dates in the whole array. By "large", I meant that the array which I have appended is not the complete array. It has a total of 48 rows and each row has different number of columns.
Mohit Sharma
Mohit Sharma el 19 de Jul. de 2015
I have attached the text file. It would be really great if you could tell how to get exactly that 53.829775 (which is written after date in that file) in one variable
Image Analyst
Image Analyst el 19 de Jul. de 2015
48 is far, far from large. Large would be like hundreds of millions or billions. In addition, "large" does not mean "not complete", it means "big".
per isakson
per isakson el 19 de Jul. de 2015
Editada: per isakson el 19 de Jul. de 2015
Then the first three lines of the function, ccsm, will do the job, i.e. "I want to have only 53.829775". A good thing with this solution is that it doesn't depend on "rows" and "columns". Less good is that it takes some effort to get used to regular expressions. (The Matlab documentation of regular expression is okey - imo.)
Mohit Sharma
Mohit Sharma el 20 de Jul. de 2015
I am facing problem implementing fileread function. Whenever I execute it, it says "no such file or directory" for my file's name. I tried using fullfile function to locate the path of my file, but I still get the same error. Any help will be appreciated. Thanks.
Then it does not exist. Check with this:
fullFileName = fullfile(folder, 'cssm.txt');
if exist(fullFileName, 'file')
uiwait(helpdlg('It exists'));
else
message = sprintf('File %s does not exist', fullFileName);
uiwait(warndlg(message));
end
Mohit Sharma
Mohit Sharma el 20 de Jul. de 2015
Thanks a lot, I now get the result what per isakson was having. It would be great if I can have the 2 values which we get in "num" in two different variables. Kindly help.
Mohit Sharma
Mohit Sharma el 20 de Jul. de 2015
I got that. Thanks a lot for helping me out. I owe you people a treat :)

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 19 de Jul. de 2015

Editada:

el 20 de Jul. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by