In order to run MATLAB code in a code file, the name of that file must satisfy the requirements given by the isvarname function. Those requirements are:
- The name must start with a letter (upper-case or lower-case doesn't matter.)
- The name must contain only letters, numbers, and/or the underscore character.
- The name must be no longer than the output of the namelengthmax function (currently 63.)
- The name must not be a keyword in MATLAB. [This requirement can be relaxed or ignored in certain circumstances, but regardless it's not what's causing Run Section to fail to work.]
Does your name satisfy these requirements? No, it doesn't.
name = 'matlab reflection coefficients.m';
[~, nameNoExt] = fileparts(name)
nameNoExt = 'matlab reflection coefficients'
This name satisfies the first requirement:
the third requirement:
strlength(nameNoExt) <= namelengthmax
and the fourth requirement:
It fails the second.
isUnderscore = nameNoExt == "_";
isLetterOrDigit = isstrprop(nameNoExt, 'alphanum');
letter_digit_or_underscore = isLetterOrDigit | isUnderscore;
all(letter_digit_or_underscore)
Which characters are not letters, digits, or underscores? The spaces.
invalidCharacters = nameNoExt(~letter_digit_or_underscore)
Rename your code file to a name that satisfies all the requirements. You could replace the spaces with the underscore character, or you could remove the spaces (perhaps capitalizing the first letter of each word after the first.) The matlab.lang.makeValidName function can suggest a valid name similar to the name you specified.
newname = matlab.lang.makeValidName(nameNoExt)
newname = 'matlabReflectionCoefficients'