%% Import Comma-Separated Data
% This example shows how to import comma-separated numeric data from a text file. Create a sample file, read all the data in the file, and then read only a subset starting from a specified location.
% Create a sample file named ph.dat that contains comma-separated data and display the contents of the file.

A = 0.9*gallery('integerdata',99,[3 4],1);
writematrix(A,'ph.dat','Delimiter',',')
type('ph.dat')

% Read the file using the readmatrix function. The function returns a 3-by-4 double array containing the data from the file.

M = readmatrix('ph.dat')

% Import only the rectangular portion of data starting from the first row and third column in the file. Create an import options object and specify the columns and rows to import using the SelectedVariableNames and DataLines properties. Then, import the selected portion of the data from the file.

opts = detectImportOptions('ph.dat');
opts.SelectedVariableNames = {'Var3','Var4'};
opts.DataLines = [1 3];
readmatrix('ph.dat',opts)

% Copyright 2015 The MathWorks, Inc.