Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

setfield

Set content of specific field

Syntax

newfts = setfield(tsobj, field, V)
newfts = setfield(tsobj, field, {dates}, V)

Description

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 character vectors or a cell of a date character vector's range using the :: operator, for example,
'03/01/99::03/31/99'. Dates can contain time-of-day information.

Examples

Example 1. Set the closing value for all days to 3890.

load dji30short 
format bank
myfts1 = setfield(myfts1, 'Close', 3890) 
myfts1 = 
 
    desc:  DJI30MAR94.dat
    freq:  Daily (1)

    'dates:  (20)'    'Open:  (20)'    'High:  (20)'    'Low:  (20)'    'Close:  (20)'
    '04-Mar-1994'     [    3830.90]    [    3868.04]    [   3800.50]    [     3890.00]
    '07-Mar-1994'     [    3851.72]    [    3882.40]    [   3824.71]    [     3890.00]
    '08-Mar-1994'     [    3858.48]    [    3881.55]    [   3822.45]    [     3890.00]
    '09-Mar-1994'     [    3853.97]    [    3874.52]    [   3817.95]    [     3890.00]
    '10-Mar-1994'     [    3852.57]    [    3865.51]    [   3801.63]    [     3890.00]
    '11-Mar-1994'     [    3832.58]    [    3872.83]    [   3806.69]    [     3890.00]
    '14-Mar-1994'     [    3870.29]    [    3894.21]    [   3835.96]    [     3890.00]
    '15-Mar-1994'     [    3863.41]    [    3888.46]    [   3826.85]    [     3890.00]
    '16-Mar-1994'     [    3851.03]    [    3879.53]    [   3819.94]    [     3890.00]
    '17-Mar-1994'     [    3853.62]    [    3891.34]    [   3821.66]    [     3890.00]
    '18-Mar-1994'     [    3865.42]    [    3911.78]    [   3838.65]    [     3890.00]
    '21-Mar-1994'     [    3878.38]    [    3898.25]    [   3838.65]    [     3890.00]
    '22-Mar-1994'     [    3865.71]    [    3896.23]    [   3840.66]    [     3890.00]
    '23-Mar-1994'     [    3868.88]    [    3901.41]    [   3839.80]    [     3890.00]
    '24-Mar-1994'     [    3849.88]    [    3865.42]    [   3792.58]    [     3890.00]
    '25-Mar-1994'     [    3827.13]    [    3826.85]    [   3774.73]    [     3890.00]
    '28-Mar-1994'     [    3776.46]    [    3793.45]    [   3719.74]    [     3890.00]
    '29-Mar-1994'     [    3757.17]    [    3771.86]    [   3689.23]    [     3890.00]
    '30-Mar-1994'     [    3688.36]    [    3718.88]    [   3612.36]    [     3890.00]
    '31-Mar-1994'     [    3639.71]    [    3673.10]    [   3544.12]    [     3890.00]

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]

Related Examples

Introduced before R2006a

Was this topic helpful?