I have found extractBefore, but how do I succinctly apply it to each opts.VariableNames element? Should I use cellfun? I will try it instead of a for loop, but I don't see how to use cellfun for a function requiring an input argument (namely, '_').
Why does MATLAB not allow for the following 'intuitive' syntax?
>> opts.VariableNames(:) = extractBefore(opts.VariableNames(:),'_')Error using matlab.io.ImportOptions/set.VariableNames (line 185)Expected a cell array of valid variable names.>> opts.VariableNames = extractBefore(opts.VariableNames,'_')Error using matlab.io.ImportOptions/set.VariableNames (line 185)Expected a cell array of valid variable names.
The following code is what I am seeking to improve with this task, by automatically truncating the latter column names.
filepath = 'easy.csv';opts = detectImportOptions(filepath, 'NumHeaderLines', 1);opts = setvartype(opts,opts.VariableNames, 'double');opts.VariableNames(1)={'Dose'};DVH = readtable(filepath,opts)
Best Answer