| Contents | Index |
newfts = setfield(tsobj, field, V)
newfts = setfield(tsobj, field, {dates}, V)
setfield treats the contents of fields in a time series object (tsobj) as fields in a structure.
newfts = setfield(tsobj, field, V) sets the contents of the specified field to the value V. This is equivalent to the syntax S.field = V.
newfts = setfield(tsobj,
field, {dates}, V) sets the contents of the specified field
for the specified dates. dates can be individual
cells of date strings or a cell of a date string range using the :: operator,
for example,
'03/01/99::03/31/99'.
Dates can contain time-of-day information.
Example 1. Set the closing value for all days to 3890.
load dji30short format bank myfts1 = setfield(myfts1, 'Close', 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]
chfield | fieldnames | getfield | isfield | rmfield
View demos and recorded presentations led by industry experts.
Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |