0

I download data from Yahoo! Finance with:

data = getYahooDailyData({'MSFT', 'axp'},'01/01/2000', '01/01/2015', 'dd/mm/yyyy');

and the data is stored as a 1x1 struct. I now want to create a Tx2 matrix of the daily adjusted closing prices for MSFT and axp, which is column 7 in each table in the struct.

How can I do that?

Or better: Is there a way to make computations directly on the information/prices in the struct?

Suever
  • 64,497
  • 14
  • 82
  • 101

1 Answers1

1

You can actually access the data in your struct by name.

vecMsftAdj = data.MSFT.AdjClose;
vecAxpAdj  = data.axp.AdjClose;

% if you want n x 2 matrix
mAdjClose = [vecMsftAdj, vecAxpAdj];

% I personnaly prefer working with table
tAdjClose = table;
tAdjClose.MsftAdj = vecMsftAdj;
tAdjClose.AxpAdj  = vecAxpAdj;
  • Great, thanks! What is the upside of working with table instead of double? I'm not familiar with either struct or table, but I assume that there are some great advantages. – thomlei Apr 15 '15 at 13:39
  • Also: What if I have not 2 stocks, but the 500 from S&P500. Is it possible to run a loop creating a matrix similar to mAdjClose, but now Tx500? Or TxN for that matter? – thomlei Apr 15 '15 at 13:50