Run Section funcionality isn't working
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Shaoming
el 18 de Sept. de 2023
Respondida: Steven Lord
el 18 de Sept. de 2023
I click on the "Run Section" button and it doesn't do anything.
It used to function correctly, but only this time when I open matlab it doesn't work.
It's nothing to do with the file name right?

1 comentario
Respuesta aceptada
Steven Lord
el 18 de Sept. de 2023
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) % Name without the extension
isvarname(nameNoExt)
This name satisfies the first requirement:
isletter(nameNoExt(1))
the third requirement:
strlength(nameNoExt) <= namelengthmax
and the fourth requirement:
~iskeyword(nameNoExt)
It fails the second.
isUnderscore = nameNoExt == "_";
isLetterOrDigit = isstrprop(nameNoExt, 'alphanum'); % letters or digits
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)
isvarname(newname)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Whos en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!