Main Content

Import Tabular Data from Files

Import Data from Text File

Use table to store tabular data that you can use later in fitting and other analyses at the command line. Use readtable to import data without NONMEM® interpretation of column headers. Remove any comments that are present at the beginning of the file before importing.

data = readtable("tobramycin.txt");
head(data)
    ID    TIME    CP    EVID    DOSE    MDV     WT     HT     AGE    SEX    CLCR
    __    ____    __    ____    ____    ___    ____    ___    ___    ___    ____

    1       0     0      3      100      1     58.4    164    71      1      58 
    1       8     0      1       80      1     58.4    164    71      1      58 
    1      16     0      1       80      1     58.4    164    71      1      58 
    1      24     0      1       80      1     58.4    164    71      1      58 
    1      32     0      1       80      1     58.4    164    71      1      58 
    1      40     0      1       80      1     58.4    164    71      1      58 
    1      48     0      1       80      1     58.4    164    71      1      58 
    1      56     0      1       80      1     58.4    164    71      1      58 

The readtable function also lets you use name-value arguments in which you can specify options such as the type of delimiter and whether the first row contains header names.

data2 = readtable("tobramycin.txt",TreatAsMissing=".");

If you want to use the data for fitting using sbiofit or sbiofitmixed, convert the data to a groupedData format.

gd = groupedData(data2);
head(gd)
ans =

  8x11 groupedData

    ID    TIME    CP    EVID    DOSE    MDV     WT     HT     AGE    SEX    CLCR
    __    ____    __    ____    ____    ___    ____    ___    ___    ___    ____

    1       0     0      3      100      1     58.4    164    71      1      58 
    1       8     0      1       80      1     58.4    164    71      1      58 
    1      16     0      1       80      1     58.4    164    71      1      58 
    1      24     0      1       80      1     58.4    164    71      1      58 
    1      32     0      1       80      1     58.4    164    71      1      58 
    1      40     0      1       80      1     58.4    164    71      1      58 
    1      48     0      1       80      1     58.4    164    71      1      58 
    1      56     0      1       80      1     58.4    164    71      1      58 

For details on how to format a data file for fitting, see Create Data File with SimBiology Definitions.

Importing Data from NONMEM-Formatted Files

Use the sbionmimport function to import data from NONMEM® formatted files. To import the data without NONMEM interpretation of column headers, see Import Data from Text File.

To prepare the data file for import, remove any comments that are present at the beginning of the file and select one of the following methods to import your data:

  • If the data file contains only the column header values shown in Support for Importing NONMEM Formatted Files, use the following syntax.

    filename = 'C:\work\datafiles\dose.xls';
    ds = sbionmimport(filename);
  • If the data file has column header labels different from the table shown in Support for Importing NONMEM Formatted Files and you want to apply NONMEM interpretation of headers:

    1. Create a NONMEM file definition object. This object lets you define what the column headers in the data file mean in SimBiology®. In the following example, the column containing response values is CP, whereas in NONMEM formatted files the column is labelled DV.

      For instance, to use the tobramycin data set [1] (open this example to get the data), first create a NONMEM file definition object and define the following:

      def = sbionmfiledef;
      def.DoseLabel = 'DOSE';
      def.GroupLabel = 'ID';
      def.TimeLabel = 'TIME';
      def.DependentVariableLabel = 'CP';
      def.MissingDependentVariableLabel = 'MDV';
      def.EventIDLabel = 'EVID';
      def.ContinuousCovariateLabels = {'WT', 'HT', 'AGE', 'SEX', 'CLCR'};

      Your file can contain any name for column headings. See sbionmfiledef for the list of properties you can configure in the NONMEM file definition object.

    2. Use the sbionmimport function to import your data file with the column header definitions as specified in the NONMEM file definition object).

      The sbionmimport function accepts name-value arguments accepted by dataset. For example, if the data set does not contain column headers, use 'ReadVarNames',false to specify that sbionmimport should read values from the first row of the file.

      data = sbionmimport('tobramycin.txt',def,'TreatAsEmpty','.');

For information about creating a model to fit the data, see Create a Pharmacokinetic Model Using the Command Line.

Other Resources for Importing Data

For detailed information about supported data formats and the functions for importing data into the MATLAB® Workspace, see Supported File Formats for Import and Export.

You also can import data using the MATLAB Import Wizard to import data as text files (such as .txt and .dat), MAT-files, and spreadsheet files, (such as .xls).

The MATLAB Import Wizard processes the data source. The wizard recognizes data delimiters, as well as row or column headers, to facilitate the process of data selection and importation into the MATLAB Workspace. You can import the data to the SimBiology Model Analyzer app from the MATLAB Workspace.

See Also

| | |

Related Topics