主要内容

CreateData

Create data object in a project object

    Description

    DataObj = CreateData(ProjObj) creates a data object in a project object ProjObj. If you do not want to associate a data object with a project object use the mbcmodel namespace function, mbcmodel.CreateData.

    example

    DataObj = CreateData(ProjObj,Filename) creates a data object in a project object ProjObj. The data is in a file, filename, specified as a character vector containing the full path to the file.

    DataObj = CreateData(ProjObj,Table) creates a data object in a project object ProjObj. The data is contained in a table object, Table.

    DataObj = CreateData(ProjObj,mbcStruct) creates a data object for an MBC data structure in a project object ProjObj. mbcStruct is the MBC data structure name.

    DataObj = CreateData(ProjObj,Filename,Filetype) creates a data object in a project object ProjObj. The data is in a file, Filename, specified as a character vector containing the full path to the file. Filetype is a character vector specifying the file type.

    Examples

    collapse all

    Create data object in a project object from file.

    proj = mbcmodel.CreateProject();
    file = fullfile(matlabroot, 'toolbox', ...
                    'mbc', 'mbctraining', 'holliday.xlsx');
    data = CreateData(proj, file);

    ProjObj is an mbcmodel.project object.

    Input Arguments

    collapse all

    Project object, specified as a mbcmodel.project object.

    Project file path, specified as a character vector.

    If you do not specify a Filename, no data is loaded into the new data object. Load data using ImportFromFile, provided that you enable editing of the data object by using BeginEdit. Call CommitEdit to apply edits.

    If you create the data object specifying a filename, then the Name property is set to the filename. However, if you use ImportFromFile after creation to load data from a file, the name of the data object does not change.

    Data Types: char | string

    Table object.

    Data Types: char | string

    An MBC data structure is a structure array that contains these fields:

    • varNames — Cell array of character vectors that hold the names of the variables in the data (1xn or nx1).

    • varUnits — Cell array of character vectors that hold the units associated with the variables in varNames (1xn or nx1). If array is empty, no units are defined.

    • data — Array that holds the values of the variables (mxn).

    • comment — Optional character vector holding comment information about the data.

    Character vector specifying the file type. See DataFileTypes for the specification of allowed file types. If filetype is not provided, the software infers the file type from the file extension.

    Data Types: char | string

    Output Arguments

    collapse all

    Data object, returned as a mbcmodel.data object.

    Version History

    Introduced before R2006a