%% Import data from text file. % Script for importing data from the following text file: % % C:\Users\Barbara Karl\Documents\MATLAB\Auswertung-2018-ZVM\2018-zvm-oktober.csv % % To extend the code to different selected data or a different text file, % generate a function instead of a script. % Auto-generated by MATLAB on 2018/11/14 10:43:37 %% Initialize variables. filename = 'C:\Users\Barbara Karl\Documents\MATLAB\Auswertung-2018-ZVM\2018-zvm-oktober.csv'; delimiter = ';'; %% Read columns of data as text: % For more information, see the TEXTSCAN documentation. formatSpec = '%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%q%[^\n\r]'; %% Open the text file. fileID = fopen(filename,'r','n','UTF-8'); % Skip the BOM (Byte Order Mark). fseek(fileID, 3, 'bof'); %% Read columns of data according to the format. % This call is based on the structure of the file used to generate this % code. If an error occurs for a different file, try regenerating the code % from the Import Tool. dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'TextType', 'string', 'ReturnOnError', false); %% Close the text file. fclose(fileID); %% Convert the contents of columns containing numeric text to numbers. % Replace non-numeric text with NaN. raw = repmat({''},length(dataArray{1}),length(dataArray)-1); for col=1:length(dataArray)-1 raw(1:length(dataArray{col}),col) = mat2cell(dataArray{col}, ones(length(dataArray{col}), 1)); end numericData = NaN(size(dataArray{1},1),size(dataArray,2)); %% Split data into numeric and string columns. rawNumericColumns = {}; rawStringColumns = string(raw(:, [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23])); %% Create output variable zvmoktober = raw; %% Clear temporary variables clearvars filename delimiter formatSpec fileID dataArray ans raw col numericData rawNumericColumns rawStringColumns;