This is possibly because you may not be properly loading the data from the text or excel file to MATLAB.
You can read through the below links to know how to read these files into MATLAB workspace:
Once you load the variable to MATLAB workspace, make sure that the variable is of proper numeric data type.
Note :The input argument to the function 'length' has to be Input array, specified as a numeric array, character array, logical array, structure, cell array, categorical array, datetime array, duration array, or calendarDuration array.
Hope the above suggestions are helpful.