To get the time value from a large array
Afficher commentaires plus anciens
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 commentaires
Image Analyst
le 19 Juil 2015
How large is it? How many gigabytes? You might have to use memmapfile() if it's really big.
Jan
le 19 Juil 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
le 19 Juil 2015
Modifié(e) : per isakson
le 19 Juil 2015
Réponses (2)
Image Analyst
le 19 Juil 2015
0 votes
Have you seen COMTRADE Reader: http://www.mathworks.com/matlabcentral/fileexchange/15619-comtrade-reader? Does it do what you want?
2 commentaires
Mohit Sharma
le 19 Juil 2015
Image Analyst
le 20 Juil 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.
per isakson
le 19 Juil 2015
Modifié(e) : per isakson
le 20 Juil 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
 
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 commentaires
Mohit Sharma
le 19 Juil 2015
Mohit Sharma
le 19 Juil 2015
Image Analyst
le 19 Juil 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
le 19 Juil 2015
Modifié(e) : per isakson
le 19 Juil 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
le 20 Juil 2015
Image Analyst
le 20 Juil 2015
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
le 20 Juil 2015
Mohit Sharma
le 20 Juil 2015
Catégories
En savoir plus sur Text Data Preparation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!