function variables = hri_load_logfile(filename) %HRI_LOAD_LOGFILE Loads a HRI logfile to a MATLAB structure. % Loads the filename with the given filename. A MATLAB structure is % generated, each named field is an array of the history of the variable % value. %% Read the header to get the variables names. fid = fopen(filename, 'r'); line = fgetl(fid); varNames = textscan(line, '%s', 'Delimiter', ';'); varNames = varNames{:}; %% % Replace the special characters by '_'. for i = 1:length(varNames) varName = varNames{i}; varName((varName < 'a' | varName > 'z') & ... (varName < 'A' | varName > 'Z') & ... (varName < '0' | varName > '9')) = '_'; varNames{i} = varName; end fclose(fid); %% Read the variables values over time. A = dlmread(filename, ';', 1, 0); %% Create a structure with a field per variable. for i=1:length(varNames) variables.(varNames{i}) = A(:,i); end end