Documentation Center

  • Trial Software
  • Product Updates

Importing Data

Import Data from Files

Use the dataset function to import tabular data with named columns into an array that you can use in fitting and analysis at the command line. Use this function when you want to import the data without NONMEM® interpretation of column headers. The dataset function lets you specify parameter/value pair arguments in which you can specify options such as the type of delimiter, and whether the first row contains header names. For more information, see dataset.

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

Examples:

% text files
data = dataset('file', 'tobramycin.txt')
% text files with . in place of missing values
data = dataset('file', 'tobramycin.txt', 'TreatAsEmpty', '.')
% For Excel files
data = dataset('xlsfile', 'tobramycin.xls')

You can also construct the dataset array from variables in the MATLAB Workspace.

% Create a 10x2 array
x = rand(10,2);
% Construct a dataset array containing x
data = dataset({x(:, 1), 'Column1'}, {x(:,2), 'Column2'})

If you import the data as separate variables containing doubles, you can construct the dataset array by concatenating the variables.

% Create 2 10x1 vectors 
x = rand(10,1);
y = rand(10,1);
% Construct a dataset array containing x and y
data = dataset({x, 'Column1'}, {y, 'Column2'})

After you finish analyzing your data, you can export any new variables in the MATLAB® Workspace to a variety of file formats.

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 the Methods for Importing Data.

You also can import data using the MATLAB Import Wizard (see Import Images, Audio, and Video Interactively. Use the 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 desktop from the MATLAB Workspace.

Was this topic helpful?