Is there a more effitiant way than 'datenum(num2str(FTStempIn(:,1:1))'
5 views (last 30 days)
Show older comments
Scragmore on 19 Nov 2011
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.
Tik = num2str(InstIn);
ConCatQuery = ['SELECT DISTINCT yyyymmdd,Time,Open,High,Low,Close FROM Forex_GBP_USD WHERE yyyymmdd > (',Tik,')'];
conn = database('Dougy','','');
curs = exec(conn, ConCatQuery);
curs = fetch(curs);
FTStempIn = curs.Data;
FTStempOut = [datenum(num2str(FTStempIn(:,1:1)), 'yyyymmdd') FTStempIn(:,3:6)];
InstOut = FTStempOut;
%InstOut = curs.Data;
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
More Answers (0)
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!