MATLAB: Expression representation in an Iteration

optimizationOptimization Toolbox

I'd love to know how i can express the expression in a loop. n is the iteration number. I know it may seem trivial but i've been cracking my skull over it. My approach, which I figure is wrong anyways, was to index the second term with n. But the iteration number is greater than the the matrix elements and i get an error. Here is my attempt at the issue.
w=[randn(2,1)+ij*randn(2,1)];
W_k=w*ctranspose(w);
for n=1:N;
w=[randn(2,1)+ij*randn(2,1)];
W_k1=w*ctranspose(w);
t=W_k - W_k1;
end
Is this doing what the expression requires?

Best Answer

W_k = cell(N,1);
w=[randn(2,1)+ij*randn(2,1)];
W_k{1} = w*ctranspose(w);
for n=1:N;
w = randn(2,1)+ij*randn(2,1);
W_k{n+1} = w*ctranspose(w);
t = W_k{n} - W_k1{n+1};
%do something with t
end