MATLAB Answers

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

3 ビュー (過去 30 日間)
Scragmore 2011 年 11 月 19 日
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','','');
setdbprefs('DataReturnFormat', 'numeric');
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
Walter Roberson 2011 年 11 月 19 日
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 件のコメント
Scragmore 2011 年 11 月 22 日
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


その他の回答 (0 件)



Community Treasure Hunt

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

Start Hunting!

Translated by