Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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 Kommentare
Jan
Jan am 3 Apr. 2012
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 am 3 Apr. 2012
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Thomas
Thomas am 3 Apr. 2012
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 Kommentare
Jan
Jan am 4 Apr. 2012
This solution does not pre-allocate the results. This will slow down the process substantially.
Thomas
Thomas am 4 Apr. 2012
Yes. If you preallocate 'z' and 'l' the code will be much faster..

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

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

Kategorien

Mehr zu Time Series Events finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by