Graphics | ![]() ![]() |
Using Variables in Text Strings
Any string variable is a valid specification for the text String
property. For example, each row of the matrix PersonalData
contains specific information about a person (note that all but the longest row is padded with a space so that each has the same number of columns).
PersonalData = ['Jack Straw ';'489 Main St.';'Wichita KN '];
To display the data, index into the desired row.
text(x1,y1,['Name: ',PersonalData(1,:)]) text(x2,y2,['Address: ',PersonalData(2,:)]) text(x3,y3,['City and State: ',PersonalData(3,:)])
You can specify numeric variables in text strings using the num2str
(number to string) function. For example, if you type on the command line,
x = 21; ['Today is the ',num2str(x),'st day.']
MATLAB concatenates the three separate strings into one.
Today is the 21st day.
Since the result is a valid string, you can specify it as a value for the text String
property.
text(xcoord,ycoord,['Today is the ',num2str(x),'st day.'])
![]() | Including Symbols and Greek Letters in Text Strings | Example - Multiline Text | ![]() |