MATLAB - Strings
MATLAB - Strings
Menu Login
Coding
HTML Ground
CSS Javascript SQL Python Java C C++ PHP Scala C#
Category
Jobs
Development
MATLAB - Strings
Academic Tutorials
Whiteboard
Computer Science
Creating a character string is quite simple in MATLAB. In fact, we have used it
many Databases
times. For example, you type the following in the command prompt −
DevOps
my_string = 'Tutorials Point' Live Demo
Digital Marketing
Engineering
MATLAB Tutorials
will execute the above statement and return the following result −
Exams Syllabus
my_string = Tutorials Point
Famous Monuments
MATLAB considers all variables as arrays, and strings are considered as
GATE
character ExamsLet us use the whos command to check the variable created
arrays.
above −
Latest Technologies
whosMachine Learning
Mainframe Development
MATLAB will execute the above statement and return the following result −
Management Tutorials
Name Size Bytes Class Attributes
Mathematics
my_string 1x16Tutorials 32 char
Microsoft Technologies
Interestingly, you can use numeric conversion functions like uint8 or uint16 to
Misc
convert thetutorials
characters in the string to their numeric codes. The char function
https://www.tutorialspoint.com/matlab/matlab_strings.htm 1/11
9/20/23, 5:40 PM MATLAB - Strings
Example
Java Technologies
CreatePython Technologies
a script file and type the following code into it −
SAP Tutorials
Soft Skills
When you run the file, it displays the following result −
Telecom Tutorials
str_ascii =
UPSC IAS Exams
84 117 116 111 114 105 97 108 39 115 32 80 111 105 110 116
Web Development
https://www.tutorialspoint.com/matlab/matlab_strings.htm 2/11
9/20/23, 5:40 PM MATLAB - Strings
Example
Login
Create a script file and type the following code into it −
doc_profile =
Zara Ali
Sr. Surgeon
R N Tagore Cardiology Research Center
doc_profile =
Zara Ali
Sr. Surgeon
RN Tagore Cardiology Research Center
https://www.tutorialspoint.com/matlab/matlab_strings.htm 3/11
9/20/23, 5:40 PM MATLAB - Strings
Example
However, a more efficient way to combine the strings is to convert the resulting
array into a cell array.
MATLAB cell array can hold different sizes and types of data in an array. Cell
arrays provide a more flexible way to store strings of varying length.
The cellstr function converts a character array into a cell array of strings.
Example
https://www.tutorialspoint.com/matlab/matlab_strings.htm 4/11
9/20/23, 5:40 PM MATLAB - Strings
profile = cellstr(profile);
disp(profile)
{
[1,1] = Zara Ali
[2,1] = Sr. Surgeon
[3,1] = R N Tagore Cardiology Research Center
}
Function Purpose
https://www.tutorialspoint.com/matlab/matlab_strings.htm 6/11
9/20/23, 5:40 PM MATLAB - Strings
Examples
Formatting Strings
ans = 3141.592654
3141.59
+3141.59
3141.59
000003141.59
Joining Strings
https://www.tutorialspoint.com/matlab/matlab_strings.htm 7/11
9/20/23, 5:40 PM MATLAB - Strings
str1 = red-blue-green-yellow-orange
str2 = red,blue,green,yellow,orange
new_student =
{
[1,1] = Poulomi Dutta
}
first_names =
{
[1,1] = Zara
[1,2] = Neha
[1,3] = Monica
[1,4] = Madhu
[1,5] = Madhu
[1,6] = Bhawna
[1,7] = Nuha
[1,8] = Reva
[1,9] = Sunaina
[1,10] = Sofia
}
https://www.tutorialspoint.com/matlab/matlab_strings.htm 8/11
9/20/23, 5:40 PM MATLAB - Strings
Comparing Strings
Get Started
https://www.tutorialspoint.com/matlab/matlab_strings.htm 9/11
9/20/23, 5:40 PM MATLAB - Strings
Advertisements
Affiliates eBooks
https://www.tutorialspoint.com/matlab/matlab_strings.htm 10/11
9/20/23, 5:40 PM MATLAB - Strings
Contact Us
Tutorials Point India Private Limited,
Incor9 Building, Kavuri Hills, Madhapur,
Hyderabad, Telangana - 500081, INDIA
https://www.tutorialspoint.com/matlab/matlab_strings.htm 11/11