Q:

Matlab: How to calculate return for every stock

tr9sh, thanks for editing the question, but I have to clarify I didn't ask for calculating daily return. What I want is to calculate annual return by locating the row of the date without enter the data 'price' . The formula would look like this: (price(2001/1/20)/price(2000/1/21) - 1)
The closing price for 'n stocks in n period' is imported into Matlab like this: 
2000/1/1  23.4  78.9 ...
2000/1/2  23.3  67.1 ...
...
2001/1/1 23.2 77.1 ...
2001/1/2 24.1 78.1 ...
The number in each column is the price for each stock. If I want to calculate the annual return  for each of them, how should my code look? 
I have tried 
Return = (filename(find(2001/1/1)),2)/(filename(find(2000/1/1)),2) - 1

A:

I don't quite know what you want, but the following solution may work for you. Say your data is stored in the matrix X. Then
close = X(:,2:end);
ret   = close(2:end,:) ./ close(1:end-1,:) - 1;
dates = X(2:end,1);

