0

I hope this is a simple enough question, but I am a beginner and haven't managed it on my own after several sessions.

I have a 1x29 struct of financial market data with 8 fields: stock_market. the first field is the date

the first 11 'rows' of the struct

As you can see, not all the components of the stock market i.e. the stocks have the same length time series (some comanies are newer than others or have since left the market etc.)

I would like to know in general how best to manipulate such an uneven struct of time series data. One specific example is that I'd like to write a function that can extract the 'Date' and 'AdjClose' (adjusted closing price) from the struct, for one individual stock, and plot that on a graph, with the dates shown/labelled on the x-axis and prices on the right. An extension is to plot several AdjClose time series on one x-axis together, even though the length of their respective Date values are different. I don't want to pad these strings out so that I have lines running along zero for a portion of the graph. Other more complicated functions shouldn't be difficult once I could manage this task.

I haven't shared any code, as it is simply 'plot(stock_market(1).Date, stock_market(1).AdjClose)` and mostly red with errors. I have read a few discussions about padding, but like i mentioned above, don't want to pad with zeros or any other number for the diagrams. For other functions, I may have to pad them, but if anyone has a different solution - it'd be great to hear it :-)

Thanks in advance.

n1k31t4
  • 2,745
  • 2
  • 24
  • 38
  • 1
    What about padding with `NaN` ? They don't show up in plots. – marsei Mar 04 '14 at 22:25
  • Have you considered the use of length() to determine how long something is? – EngrStudent Mar 04 '14 at 22:44
  • Can you give an example of the exact error you are getting when you are plotting? Also, are the contents of the different struct simply numerical? I don't see why the plotting function is giving you errors. – Lazarus Mar 04 '14 at 23:42
  • @Lazarus: The `Date` field is a cell, not numerical. the plot function won't accept it as an input. '"Conversion to double from cell not possible"'. @EngrStudent: I know the lengths already, which may be useful in the end, sure - but I don't know how yet. @Macduff: I am currently doing this using the `NaN` function - good odea, thanks! – n1k31t4 Mar 05 '14 at 17:22
  • 1
    Use cell2mat to convert the cell to a numerical array. – Lazarus Mar 06 '14 at 03:15

0 Answers0