first argument must be a string array, character vector, or cell array of character vectors. error in ts/totable (line 38) [n, modified1] = matlab.lang.makevalidname(input.name); in matlab

The error message you encountered is "first argument must be a string array, character vector, or cell array of character vectors". This error occurred in the totable function on line 38, specifically in the line [n, modified1] = matlab.lang.makevalidname(input.name);.

To resolve this error, make sure that the input argument input.name is of the correct type. totable function expects the input argument to be a string array, a character vector, or a cell array of character vectors.

Here are a few steps you can follow to resolve this error:

  1. Check the type of your input.name variable. Verify if it is indeed a string array, character vector, or cell array of character vectors. You can use the class function to inspect its type.
main.m
disp(class(input.name))
24 chars
2 lines
  1. If the type of input.name is not one of the expected types, you can convert it to the correct type. For example, if input.name is a cell array of strings, you can use the cellstr function to convert it into a string array.
main.m
input.name = cellstr(input.name);
34 chars
2 lines
  1. If the type of input.name is correct, but you still encounter the error, you may need to check the elements of the string array or cell array for any invalid characters. The makevalidname function is used to replace any invalid characters with valid ones. You can use the function on individual elements of the array or cell array before passing it to totable.
main.m
n = cell(size(input.name));
modified1 = cell(size(input.name));
for i = 1:numel(input.name)
    [n{i}, modified1{i}] = matlab.lang.makevalidname(input.name{i});
end
165 chars
6 lines

Once you have made the necessary changes, you can try running your code again and see if the error persists.

gistlibby LogSnag