MATLAB: str2num (convert strings to numbers - double data type)

Опубликовано: 20 Октябрь 2024
на канале: Engineering with Dr. Kelsey Joy
1,061
14

This short covers the MATLAB built-in function STR2NUM() used for converting strings to doubles.

STR2NUM() converts numbers that are currently a string or char data type to a double data type, so they can be used as a number. There are more limitations on the types of incorrect data you can input for str2num in comparison to str2double. One benefit of str2num over str2double is you can use this for some arrays of numbers, which will not work for str2double.

STR2DOUBLE() is a similar function that also converts string versions of number to doubles. When an input argument does not meet this requirement (e.g., double number, text that is not a number), then the function returns NaN (for not a number), check out this video about STR2DOUBLE:    • MATLAB: str2double (convert strings t...  

For a more detailed discussion around the STR2DOUBLE() and NUM2STR() functions, check out this video:    • MATLAB: String Functions - str2double...  

NUM2STR() is a function that does the opposite - it converts double data types to strings, check out this video on it:    • MATLAB: num2str (convert numbers/doub...  

MAT2STR() is a function that is like NUM2STR() and can also work for arrays of numbers (vectors and matrices), check out this video introducing it:    • mat2str str2mat short post  

Check out this playlist of string function videos:    • MATLAB String Functions series  

Check out this playlist of MATLAB shorts:    • MATLAB shorts  

For a full MATLAB tutorial, check out this playlist:    • How to Create Programs in MATLAB (tut...