Sorry for missing explanation, code is for computing log differences for every two values of every column of matrix x. In vector y are dates for constrain that combinations must lie only within one day.

data looks like this:

Code:

Date(vector y)| Value(matrix x)
1.1.2000| 1, 2
1.1.2000| 2, 3
1.1.2000| 5, 4
...
1.1.2009| 3, 5
2.1.2009| 8, 6
2.1.2009| 4, 7
...

Elbarto, I don't understand your code so much now, have to read help to implement it, but that "datenum" function from your another advice solved my first problem, so hope you are right again

Originally Posted by

**CaptainBlack** What is the purpose of z? If this is a local variable you are dynamically redimensioning it within the innermost loop. If possible compute its final dimensions before entering any loop and initialise it with zeros(dim1,dim2).

Also you appear only to use the diagonal elements of z (in fact as far as I can tell you are only computing these). If so only compute the diagonal elements and use a vector for them not an array.

CB

If I use for example data such

Code:

y,x
1.1.2000,1
1.1.2000,2
2.1.2000,3
2.1.2000,4
3.1.2000,5
3.1.2000,6

to matrix z will be stored every outcome for loops "l" and "k" (in this case, b=1) in diagonal places as you wrote(1OU->1. outcome, 2OU->second, 3OU->third)

Code:

1OU, 0, 0
0, 2OU, 0
0, 0, 3OU

I used this way because i need to store answer for every value of loop "l" and corresponding values of "k" and in this way, so for reasons that I can't make it store the value in first zero position in vector I have to use matrix way, I can use matrix z(l+1,k) instead, but for z(i,j) I easy know where the value is in matrix z and can distinguish zeros from answer from these matlab put to empty places in the matrix. Maybe there is some way to write to first zero position in vector and I can use it instead of that matrix, but I don't know how to do it.

Can compute dimensions for "z" before, thanks for tip, but as I assume, first need to compute all restrictions for dates and maybe create another dummy variable to can correctly compute combination number for every day and sum them to compute dimensions of z, so I am not sure that this will speed it up. But I will try.

Thanks for helping me out with this.

-------------------

I solved the problem to write in last zero position in vector, shame on me that i did not see it before. I still tried to find some function for that but just set

was enough.

But i would still like to make it faster if it's possible somehow.