Filling in secondly time intervals between 15:30:00 to 22:00:00

1 次查看(过去 30 天)
Hi all I have prices which change every 15 seconds throughout the whole day.
I want to make the the price secondly rather than every 15 seconds. This is so that I can compare it to another second-second data.
Here is a sample of my data:
'26/01/2012 15:29:39' 168.008200000000
'26/01/2012 15:29:54' 168.042200000000
'26/01/2012 15:30:09' 168.022300000000
'26/01/2012 15:30:24' 167.964000000000
'26/01/2012 15:30:39' 167.968800000000
'26/01/2012 15:30:54' 167.964000000000
'26/01/2012 15:31:09' 167.973700000000
'26/01/2012 15:31:24' 167.954700000000
Like I said I want the data to be second-second from 15:30:00 to 22:00:00. So for example:
From the period of 15:30:00 - 15:30:09 we would maintain a price of 168.0422
Then from the period of 15:30:09 to 15:30:24 we would maintain a price of 168.0223 secondly.
I hope I have explained this well and I look forward to all replies.
Thanks
  4 个评论
Jan
Jan 2012-4-3
I'm not going to post my former answer again. As far as I remember I did exactly what you are asking for.
Instead of deleting you should edit the question.
Mate 2u
Mate 2u 2012-4-3
Hi Jan, my apologies. I simply tried to rephrase the question as before it was not clear and concise. Sorry if I caused any offence and thanks for the help.

请先登录,再进行评论。

采纳的回答

Thomas
Thomas 2012-4-3
try this
clc
clear all
z=[];
format long
p={'26/01/2012 15:29:39' 168.008200000000
'26/01/2012 15:29:54' 168.042200000000
'26/01/2012 15:30:09' 168.022300000000
'26/01/2012 15:30:24' 167.964000000000
'26/01/2012 15:30:39' 167.968800000000
'26/01/2012 15:30:54' 167.964000000000
'26/01/2012 15:31:09' 167.973700000000
'26/01/2012 15:31:24' 167.954700000000};
q=datenum(p(:,1),'dd/mm/yyyy HH:MM:SS'); %convert to number
one_sec=mean(diff(q))/15; %one second in datenum
for j=1:length(p) % for every value of time add one sec 14 times
for i=1:14
m=(j*15)+i-14;
z(m,:)=[q(j)+i*one_sec];
l(m,:)=[z(m),p(j,2)]; % every added second same value of col2
end
end
new_data=cell2mat(l); %convert output to mat
new_date=datestr(new_data(:,1)); % this is the date output
new_val=new_data(:,2); % this is the corresponding value
  4 个评论
Jan
Jan 2012-4-4
This solution does not pre-allocate the results. This will slow down the process substantially.
Thomas
Thomas 2012-4-4
Yes. If you preallocate 'z' and 'l' the code will be much faster..

请先登录,再进行评论。

更多回答(1 个)

Mate 2u
Mate 2u 2012-4-3
it seems like the output maybe deleting every 15th element also? A small change needs to be made?

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by