www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/ChooseDataTypeForTextDataExample.m

    %% Designate Data Type for Imported Text Data
% Import text data as a string data type by specifying import
% options.

%%
% Create an options object for the file.
opts = detectImportOptions('outages.csv');

%%
% Sepcify which variables to import using |readtable|, and then show a
% summary. The data type of the selected variables is |char|.
opts.SelectedVariableNames = {'Region','Cause'};
T = readtable('outages.csv',opts);
summary(T)

%% 
% Import text data as a |string| data type, and then create import options
% by specifying the |TextType| name-value pair.
opts = detectImportOptions('outages.csv','TextType','string');

%%
% Sepcify which variables to import using |readtable|, and then show a
% summary. The data type of the selected variables is now |string|.
opts.SelectedVariableNames = {'Region','Cause'};
T = readtable('outages.csv',opts);
summary(T)