La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.
Conversion des types de données
MATLAB® propose de nombreuses fonctions permettant de convertir des valeurs d’un type de données à un autre afin de les utiliser dans différents contextes. Par exemple, vous pouvez convertir des nombres en texte puis ajouter ce texte à des étiquettes de graphiques ou à des noms de fichiers. Vous pouvez représenter les nombres sous forme de valeurs hexadécimales ou binaires. MATLAB propose des fonctions de conversion vers ou à partir de tableaux numériques, de tableaux de caractères et de chaînes de caractères, ainsi que de tableaux categorical
, datetime
et duration
. Vous pouvez également effectuer des conversions entre des types de données regroupant les données dans des conteneurs, tels que des cell arrays, des structures, des tables et des timetables. Dans ce cas, les valeurs des données ne changent pas mais sont stockées et accessibles dans un type de conteneur différent.
Fonctions
Rubriques
- Convert Text to Numeric Values
Convert text to arrays of numeric values. Text can represent floating-point values, dates and times, and hexadecimal and binary numbers. If text represents dates and times, then you can convert the text to datetime or duration values.
- Convert Numeric Values to Text
Convert numeric values to text. Text can represent floating-point values, either with or without exponential notation, or hexadecimal or binary digits. Use these conversions to add numbers to text such as plot labels or titles.
- Unicode and ASCII Values
MATLAB stores all characters as Unicode characters. Both strings and character vectors use the same encoding. You can convert characters to their Unicode code values, and numbers to characters.
- Hexadecimal and Binary Values
Specify hexadecimal and binary values either as literals or as text. Hexadecimal and binary literals are stored as integers. You can convert text representing hexadecimal and binary values to numbers, and numbers to text representations.
- Convert Between Text and datetime or duration Values
The
datetime
andduration
data types are the recommended data types for working with dates and times. You can convert these data types to text by using thestring
function, and you can convert text to these data types by using thedatetime
andduration
functions. When you read text representing dates and times from spreadsheets and text files you can automatically convert the text todatetime
orduration
arrays. - Convert Text in Table Variables to Categorical
This example shows how to convert a variable in a table from a cell array of character vectors to a categorical array.
- Valid Combinations of Unlike Classes
If you include elements of unlike classes in a matrix, MATLAB converts some elements so that all elements of the resulting matrix are of the same type. Data type conversion is done with respect to a preset precedence of classes.