

Matlab
Functions
Data Import and Export
Below, some examples are included. Use "doc
A = importdata('diabetes.dat')
You can see the contents of A by typing:
A.data
A.textdata
[X,varnames,casenames] = tblread('diabetes.dat', ',')
This uploads tabular data onto X. The first line of the file contains the names of the attributes/features, and the first column contains a label or an id for each data instance.
uiimport('diabetes_no_attribute_names.dat');
This starts a wizard that creates three matrices:
data: containing the data instances
rowheaders: containing the class labels
textdata: containing all textdata (in this case same as class labels) as the dataset is numeric.
Read formatted data from text file or string
See help or "doc textscan" to learn more about this function.
Example:
fid = fopen('contact-lenses.csv');
C = textscan(fid, '%s %s %s %s %s','delimiter', ',');
>> C{1}
ans =
'young'
'young'
'young'
'young'
'young'
'young'
'young'
'young'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'pre-presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
'presbyopic'
>> C{5}
ans =
'none'
'soft'
'none'
'hard'
'none'
'soft'
'none'
'hard'
'none'
'soft'
'none'
'hard'
'none'
'soft'
'none'
'none'
'none'
'none'
'none'
'hard'
'none'
'soft'
'none'
'none'
>> C{1}{3}
ans =
young
load - Load data from MAT-file into workspace
for example:
c = load('diabetes_numeric_only.csv');
Use Matlab's "Import Data ..." function available from the main toolbar menu: File -> Import Data and follow the prompts.
load fisheriris load hospital

![[Return to the CS Homepage]](/images/new_cs.gif)