Main Content

Import Tabular Data from Files

Import Data from Files

Use table to store tabular data that you can use later in fitting and analysis at the command line. Use readtable to import data without NONMEM® interpretation of column headers. The readtable function lets you use name-value pair arguments in which you can specify options such as the type of delimiter and whether the first row contains header names. If you want to use the data for fitting using sbiofit or sbiofitmixed, convert it to a groupedData format using groupedData.

To prepare the data file for import, remove any comments that are present at the beginning of the file.

For example:

% Text files
data = readtable('tobramycin.txt');
% Text files with . in place of missing values
data = readtable('tobramycin.txt', 'TreatAsEmpty', '.');

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 Files.

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 syntax shown in the following example:

    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.

      To use the tobramycin data set [1], 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. For example, browse to matlabroot/toolbox/simbio/simbiodemos/ (where matlabroot is the folder where MATLAB® is installed).

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

      This example shows you how to obtain the PKData object, PKDataObj, while importing, since you will use the PKData object in fitting the model later.

      The sbionmimport function accepts property-name-value pairs 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.

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