Main Content

La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.

Définir la portée des variables et générer des noms

Partager des données entre des fonctions ou des espaces de travail et générer des noms de variables valides

Chaque fonction a son propre espace de travail qui est distinct de l’espace de travail de base réservé aux scripts et à la ligne de commande. Pour connaître les techniques à privilégier pour transmettre des données d’une fonction à une autre, consultez Share Data Between Workspaces.

Fonctions

développer tout

persistentDefine persistent variable
assigninAssign value to variable in specified workspace
globalDéclarer des variables comme globales
mlockPrevent clearing function or script from memory
munlockAllow clearing function or script from memory
mislockedDetermine if function or script is locked in memory
isvarnameDetermine if input is valid variable name
matlab.lang.makeUniqueStringsConstruct unique strings from input strings
matlab.lang.makeValidNameConstruct valid MATLAB identifiers from input strings
namelengthmaxMaximum identifier length

Rubriques

  • Base and Function Workspaces

    The base workspace stores variables that you create at the command line or that a script creates when you run it from the command line or Editor. To protect the integrity of the data, every function has its own workspace that is separate from the base workspace and all other workspaces.

  • Check Variable Scope in Editor

    Use MATLAB® function and variable highlighting features to identify when and where your code uses a particular function or variable.

  • Variable Names

    Create valid variable names and avoid potential naming conflicts.

  • Transparency in MATLAB Code

    Write code that MATLAB can optimize more effectively.

Résolution des problèmes

Resolve Error: Attempt to Add Variable to a Static Workspace.

Troubleshoot errors when attempting to add variables to nested and anonymous functions. Variables used within nested and anonymous functions must be present in the text of the code. If you add a variable to the workspace of an anonymous function, a nested function, or a function that contains a nested function dynamically, MATLAB issues an error.