Is there a more effitiant way than 'datenum(n​um2str(FTS​tempIn(:,1​:1))'

3 views (last 30 days)
Hi
Profiler is telling me I am spending over 60% of my time running this part of my function, a simple import of data. What I am converting is a number field in MS access from 20111119 to Matlab datenum, I wish to add a second conversion to deal with the time 143000 (14:30:00 HHMMSS). I am currently running this on 150k lines of data. Is there a more efficient way of dealing with these two conversions.
function InstOut = LoadForexData(InstIn)
%%%%Import market data from Quaccess via ticker PK key
% 1 Ticker index ID in need to convert No to string so SQL can Run
% 2 Concatanate SQL query as variable so can be called
% 3 Config DB
% 4 set inport as cellarray
% 5 execute at cursor connnectinon to DB and run SQL
% 6 get data at cursor
% 7 load data at curor into temp varible for further analysis
% 8 load data into second temp variable performing cell to matrix on all
% numerical values and date to number on date format.
% 9 send transformed data to output
% 10 ScoobyDoo ending, raw data to output.
%1
Tik = num2str(InstIn);
%2
ConCatQuery = ['SELECT DISTINCT yyyymmdd,Time,Open,High,Low,Close FROM Forex_GBP_USD WHERE yyyymmdd > (',Tik,')'];
%3
conn = database('Dougy','','');
%4
setdbprefs('DataReturnFormat', 'numeric');
%5
curs = exec(conn, ConCatQuery);
%6
curs = fetch(curs);
%7
FTStempIn = curs.Data;
%8
FTStempOut = [datenum(num2str(FTStempIn(:,1:1)), 'yyyymmdd') FTStempIn(:,3:6)];
%9
InstOut = FTStempOut;
%10
%InstOut = curs.Data;
Thanks,
AD

Accepted Answer

Walter Roberson
Walter Roberson on 19 Nov 2011
t = FTStempIn(:,1);
hms = repmat([14 30 0],size(t,1),1]);
FTStempOut = datenum([fix(t/10000), fix(mod(t,10000)/100), mod(t,100), hms]); %1000 corrected to 10000
  4 Comments
Scragmore
Scragmore on 22 Nov 2011
Thanks for the explanation I appreciate it. Once I got the logic you used for bypassing num2str I was able to apply to my time cell and include it into the datenum function. Has cut time of function in half.
As an Excell user I was thinking along these lines but was unable to find a simple alternative to excel's left, right and mid functions. I was stuck in string thinking and didn't think math. Thanks
Regards,
AD

Sign in to comment.

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!