Financial Time Series Toolbox | ![]() ![]() |
Set content of a specific field
Syntax
Description
setfield
treats the contents of fields in a time series object (tsobj
) as fields in a structure.
newfts = setfield(
sets the contents of the specified field to the value tsobj
, field, V)
V
. This is equivalent to the syntax S.field = V
.
newfts = setfield(
sets the contents of the specified field for the specified dates. tsobj
, field, {dates}, V)
dates
can be individual cells of date strings or a cell of a date string range using the ::
operator, e.g., '03/01/99::03/31/99'
. Dates may contain time-of-day information.
Examples
Example 1. Set the closing value for all days to 3890.
Example 2. Set values for specific times on specific days.
First create a financial time series containing time-of-day data.
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]); myfts = fints(dates_times,[(1:4)'; nan; 6],{'Data1'},1,... 'My FINTS') myfts = desc: My FINTS freq: Daily (1) 'dates: (6)' 'times: (6)' 'Data1: (6)' '01-Jan-2001' '11:00' [ 1] ' " ' '12:00' [ 2] '02-Jan-2001' '11:00' [ 3] ' " ' '12:00' [ 4] '03-Jan-2001' '11:00' [ NaN] ' " ' '12:00' [ 6]
Now use setfield
to replace the data in myfts
with new data starting at 12:00 on January 1, 2001 and ending at 11:00 on January 3, 2001.
S = setfield(myfts,'Data1',... {'01-Jan-2001 12:00::03-Jan-2001 11:00'},(102:105)') S = desc: My FINTS freq: Daily (1) 'dates: (6)' 'times: (6)' 'Data1: (6)' '01-Jan-2001' '11:00' [ 1.00] ' " ' '12:00' [ 102.00] '02-Jan-2001' '11:00' [ 103.00] ' " ' '12:00' [ 104.00] '03-Jan-2001' '11:00' [ 105.00] ' " ' '12:00' [ 6.00]
See Also
chfield
, fieldnames
, getfield
, isfield
, rmfield
![]() | rsindex | size | ![]() |