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

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 个评论

Deleting your question, and then reposting it, isn't going to get results any quicker.
Hi Jonathan, I deleted it due to mistakes in the question. I rephrased it so it is much more understandable.
Thanks
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.
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.

请先登录,再进行评论。

 采纳的回答

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 个评论

Thomas it does not give an array of 23400 which it should be considering that's how many seconds are in the period? It gives a period of 21850 something where it should be 23400
That is because of the missing 15th element.. Make ur changes accordingly..
This solution does not pre-allocate the results. This will slow down the process substantially.
Yes. If you preallocate 'z' and 'l' the code will be much faster..

请先登录,再进行评论。

更多回答(1 个)

it seems like the output maybe deleting every 15th element also? A small change needs to be made?

类别

在 帮助中心 和 File Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by