Run Section funcionality isn't working
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Risposta accettata
Steven Lord
il 18 Set 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!