function [data,warnings] = TAxyFormatRead(fileName,varargin) % TAXYFORMATREAD Read xy format files (binary) % % Usage % data = TAxyFormatRead(fileName) % [data,warnings] = TAxyFormatRead(fileName) % data = TAxyFormatRead(fileName,...) % % ... add description of parameters here... % % See also: TAload, TAdataStructure % (c) 20xx, % 20xx-xx-xx % Parse input arguments using the inputParser functionality p = inputParser; % Create an instance of the inputParser class. p.FunctionName = mfilename; % Function name to be included in error messages p.KeepUnmatched = true; % Enable errors on unmatched arguments p.StructExpand = true; % Enable passing arguments in a structure p.addRequired('fileName', @(x)ischar(x) || iscell(x) || isstruct(x)); % p.addOptional('parameters','',@isstruct); p.addParamValue('combine',logical(false),@islogical); p.addParamValue('sortfiles',logical(true),@islogical); % Note, this is to be compatible with TAload - currently without function! p.addParamValue('checkFormat',logical(true),@islogical); p.parse(fileName,varargin{:}); % Assign optional arguments from parser combine = p.Results.combine; warnings = cell(0); % If no filename given if isempty(fileName) data = []; warnings{end+1} = 'No filename.'; return; end % Handling different data types of fileName parameter if iscell(fileName) if sortfiles sort(fileName); end elseif isstruct(fileName) % That might be the case if the user uses "dir" as input for the % filenames, as this returns a structure with fields as "name" if ~isfield(fileName,'name') data = []; warnings{end+1} = 'Cannot determine filename(s).'; return; end % Convert struct to cell fileName = struct2cell(fileName); fileName = fileName(1,:)'; % Remove files with leading '.', such as '.' and '..' fileName(strncmp('.',fileName,1)) = []; if sortfiles sort(fileName); end else % If filename is neither cell nor struct % Given the input parsing it therefore has to be a string if exist(fileName,'dir') % Read directory fileName = dir(fileName); % Convert struct to cell fileName = strut2cell(fileName); fileName = fileName(1,:)'; % Remove files with leading '.', such as '.' and '..' fileName(strncmp('.',fileName,1)) = []; if sortfiles sort(fileName); end elseif exist(fileName,'file') % For convenience, convert into cell array fn = fileName; fileName = cell(0); fileName{1} = fn; else % If "filename" is neither a directory nor a file... % Check whether it's only a basename fileName = dir([fileName '*']); if isempty(fileName) data = []; warnings{end+1} = 'No valid filename.'; return; end % Convert struct to cell fileName = struct2cell(fileName); fileName = fileName(1,:)'; % Remove files with leading '.', such as '.' and '..' fileName(strncmp('.',fileName,1)) = []; if sortfiles sort(fileName); end end end % Add your code here function [data,warnings] = loadFile(fileName) % LOADFILE Load file and return contents. % % fileName - string % Name of a file (normally including full path) % % data - structure % According to the toolbox data structure % % warnings - cell array of strings % Contains warnings if there are any, otherwise empty. % A few important settings % Name of the format as it appears in the file.format field formatNameString = ''; % Add code for actually importing your data here