Record iterations of loop that has a constant numel - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Record iterations of loop that has a constant numel

noah_sjnoah_sj Posts: 2Member
I have a loop that cycles through time advancing 126 days each time to calculate returns of stock prices. I would like to record the returns at each interval, however, since the number of element in the loop remains constant, I am getting an index out of bounds error. Any idea to how to fix that? Here is a sample of my code (the actual one is quite a bit longer):
for z = 1:126:883
[num, txt] = xlsread('GDX_ETF_Sector_MeanRev.xlsx', 'GLD');
start = strmatch('5/31/2006', txt(1:end), 'exact')+z;
finish = start+252;
[num, txt] = xlsread('GDX_ETF_Sector_MeanRev.xlsx', 'GLD', ['A' num2str(Istart) ':B' num2str(finish)'']);
returns = price2ret(num);

If I change it to returns(z) I get an error: In an assignment A(I) = B, the number of elements in B and
I must be the same.
If I fix this error then I get index out of bounds because numel in z remains constant.

Thanks a lot for your help!
Sign In or Register to comment.