String to Number Conversion in MATLAB (str2num)
Advertisement
This page provides MATLAB source code demonstrating the str2num function, which converts a string representation of a matrix into a numerical matrix. Essentially, it takes a character array and transforms it into a matrix containing numbers.
The str2num function is quite handy for processing data where numbers are stored as strings.
Example:
Let’s say you have the following string matrix:
input = ['10 20'
'30 40'];
Using str2num like this:
output=str2num(input)
Will produce the following numerical matrix:
output =
10 20
30 40
Key Takeaways:
str2numconverts a string representation to a numerical matrix.- It’s useful for processing data stored as strings that need to be used in numerical computations.
Explore MATLAB Data Types, Strings & Conversions
- Binary to Decimal Conversion in MATLAB
- Binary to Hex Conversion in MATLAB
- Decimal to Base-N Conversion in MATLAB
- Decimal to Binary Conversion in MATLAB
- Decimal to Hexadecimal Conversion in MATLAB (dec2hex)
- Hex to Binary Conversion in MATLAB
- Hexadecimal String to Double Conversion in MATLAB
- Number to Hexadecimal String Conversion in MATLAB
- Number to String Conversion in MATLAB (num2str)
- String to Double Conversion in MATLAB
- String to Number Conversion in MATLAB (str2num)
- MATLAB Matrix to String (mat2str)
- Base-N Number String to Decimal in MATLAB
