Financial Time Series Toolbox | ![]() ![]() |
Description
subsref
implements indexing for a financial time series object. Integer indexing or date (and time) string indexing is allowed. Serial date numbers may not be used as indices.
To use date string indexing, enclose the date string(s) in a pair of single quotation marks '
'
.
You can use integer indexing on the object as in any other MATLAB matrix. It returns the appropriate entry(ies) from the object.
Additionally, subsref
lets you access the individual components of the object using the structure syntax.
Examples
Create a time series named myfts
:
myfts = fints((datenum('07/01/98'):datenum('07/01/98')+4)',... [1234.56; 2345.61; 3456.12; 4561.23; 5612.34], [], 'Daily',... 'Data Reference');
Extract the data for the single day July 1, 1998:
myfts('07/01/98') ans = desc: Data Reference freq: Daily (1) 'dates: (1)' 'series1: (1)' '01-Jul-1998' [ 1234.6]
Now, extract the data for the range of dates July 1, 1998 through July 5, 1998:
myfts('07/01/98::07/03/98') ans = desc: Data Reference freq: Daily (1) 'dates: (3)' 'series1: (3)' '01-Jul-1998' [ 1234.6] '02-Jul-1998' [ 2345.6] '03-Jul-1998' [ 3456.1]
You can use the MATLAB structure syntax to access the individual components of a financial time series object. To get the description field of myfts
, enter
at the command line, which returns
ans = desc: Data Reference freq: Daily (1) 'dates: (5)' 'series1: (5)' '01-Jul-1998' [ 1234.6] '02-Jul-1998' [ 2345.6] '03-Jul-1998' [ 3456.1] '04-Jul-1998' [ 4561.2] '05-Jul-1998' [ 5612.3]
The syntax for integer indexing is the same as for any other MATLAB matrix. Create a new financial time series object containing both dates and times:
dates = ['01-Jan-2001';'01-Jan-2001'; '02-Jan-2001'; ... '02-Jan-2001'; '03-Jan-2001';'03-Jan-2001']; times = ['11:00';'12:00';'11:00';'12:00';'11:00';'12:00']; dates_times = cellstr([dates, repmat(' ',size(dates,1),1),... times]); anewfts = fints(dates_times,(1:6)',{'Data1'},1,'Another FinTs');
Use integer indexing to extract the second and third data items from the object.
anewfts(2:3) ans = desc: Another FinTs freq: Daily (1) 'dates: (2)' 'times: (2)' 'Data1: (2)' '01-Jan-2001' '12:00' [ 2] '02-Jan-2001' '11:00' [ 3]
For date or string enclose the indexing string in a pair of single quotation marks.
If there is one date with multiple times, indexing with only the date returns all the times for that specific date:
anewfts('01-Jan-2001') ans = desc: Another FinTs freq: Daily (1) 'dates: (2)' 'times: (2)' 'Data1: (2)' '01-Jan-2001' '11:00' [ 1] ' " ' '12:00' [ 2]
To specify one specific date and time, index with that date and time:
anewfts('01-Jan-2001 12:00') ans = desc: Another FinTs freq: Daily (1) 'dates: (1)' 'times: (1)' 'Data1: (1)' '01-Jan-2001' '12:00' [ 2]
To specify a range of dates and times, use the double colon (::
) operator:
anewfts('01-Jan-2001 12:00::03-Jan-2001 11:00') ans = desc: Another FinTs freq: Daily (1) 'dates: (4)' 'times: (4)' 'Data1: (4)' '01-Jan-2001' '12:00' [ 2] '02-Jan-2001' '11:00' [ 3] ' " ' '12:00' [ 4] '03-Jan-2001' '11:00' [ 5]
To request all the dates, times, and data, use the ::
operator without specifiying any specific date or time:
See Also
datestr
in the Financial Toolbox documentation
![]() | subsasgn | times | ![]() |