MATLAB: How to construct an empty dataset from an input file in the Statistics Toolbox 7.4 (R2010b)

datasetemptyMATLAB

I need to construct an empty dataset from a given input file; the dataset has to be empty without any content.

Best Answer

The function of creating empty dataset from an input file is not available in the Statistics Toolbox 7.4 (R2010b).
However, you can refer to following two workarounds to perform the task. To try out both of the workarounds, please download the attached "originalDataSet.csv" which is a text file with columns separated by comma.
The first workaround is to read in the data file to a dataset and delete all the rows in it:
originalData=dataset('file', 'originalDataSet.csv', 'Delimiter', ',');
originalData(1:end,:)=[]
The second workaround is to read the first row as the header and use it to construct the dataset.
originalFileName='originalDataSet.csv';
% open the input file
originalFileHandle=fopen(originalFileName);
% read in the first line as header
header=fgetl(originalFileHandle);
% create an empty dataset
originalData=dataset;
% split the header to tokens as variable names for the dataset
cols=regexp(header, ',', 'split');
% assign the variable names to the dataset
for i=1:numel(cols)
originalData.(cols{i})={};
end
originalData.Properties