# Math Help - Matlab counting syntax problem

1. ## Matlab counting syntax problem

Hi there,

I'm new to Matlab language and I need some help to complete one script. It's about computing continuous compounded returns from data as:

Code:
function z=brm(x)
[n,m]=size(x);
c=m-1;
for l=0:c
for k=l+1:m-1
z((l+1),k)=log(x(m-l))-log(x(m-k))
end
end
My problem is that i need to constrain it to compute returns only within selected period of time. I have dada matrix arranged as(Date format=d.m):
Code:
Date, Time, Value
1.1, 1430, 1
1.1, 1431, 2
1.1, 1432, 5
...
1.1, 2259, 3
2.1, 1430, 8
2.1, 1431, 4
...
I do not know how to set condition such will constrain it to prevent compute returns from lag higher than highest possible remaining lag within current day.

Can someone help and show me way?

Tom.

2. Try "datenum". In the example below I assumed your date data was a string and all from the same year (2009).

Code:
mydate = '8.5';%8th of May
A = regexp('8.5','\.','split');%spit string
D = [str2num(A{2}) str2num(A{1}) 2009];%[month  day  year]
sD = datenum(D);%convert to serial date number

%test with date serial
sD < datenum([5 9 2009])%before 9th of May
sD > datenum([5 7 2009])%after 7th of May
Code:
ans =

1

ans =

1

EDU>>
Regards Elbarto

3. Thanks for help and example mate. That function should do the work.