Im trying to calculate annual return of several stocks in a table by dividing the 12th observation on the first one, and get an error message on this code:
table = table();
table.AAPL = mean(AAPL,2);
table.AMZN = mean(AMZN,2);
table.F = mean(F,2);
table.INTC = mean(INTC,2);
table.MSFT = mean(MSFT,2);
table.TXN = mean(TXN,2);
table.UIS = mean(UIS,2);
table.XOM = mean(XOM,2);
ann_ret = table(12,:)./table(1,:);
When i write table(12,:) in the command window i get no error message, but when i try to run the code i get this error.
Error:
Subscripting into a table using one subscript (as in t(i)) or three or more subscripts (as in t(i,j,k)) is not
supported. Always specify a row subscript and a variable subscript, as in t(rows,vars).
If anyone could make a loop of some sort that would be nice as i need to calculate the annual returns for three years, meaning observation 24 and 36 from the table as well.
Best Answer