convertCharArray Converts input to make sure it is a cell array of character vectors. String arrays are transformed into character vectors, and if only one character vector is given. Output is always a cell array, also if only one character vector is given as input. Input: funcInput function input that should be checked Output: inputConverted cell array of character vectors
0001 function inputConverted = convertCharArray(funcInput) 0002 %convertCharArray 0003 % Converts input to make sure it is a cell array of character vectors. 0004 % String arrays are transformed into character vectors, and if only one 0005 % character vector is given. Output is always a cell array, also if only 0006 % one character vector is given as input. 0007 % 0008 % Input: 0009 % funcInput function input that should be checked 0010 % 0011 % Output: 0012 % inputConverted cell array of character vectors 0013 % 0014 0015 if ~isempty(funcInput) 0016 if ischar(funcInput) || isstring(funcInput) 0017 inputConverted = {char(funcInput)}; 0018 elseif ~iscell(funcInput) && ~(all(cellfun(@ischar, funcInput)) || all(cellfun(@isstring, funcInput))) 0019 error([inputname(1) ' should be a (cell array of) character vector(s)']) 0020 else 0021 inputConverted = cellstr(funcInput); 0022 end 0023 else 0024 inputConverted=[]; 0025 end 0026 end 0027