Posted by Dr. R.B.Bhatt
Send all comments and your articles to: email@example.com.
Many a times it is required to write subscript and superscript in titles, x-axis labels, and y-axis labels for plots generated by MATLAB's plot command. Till MATLAB 5.x it was not possible. However, since MATLAB 6.x onwards, MATLAB has become really a rich tool for graphics and visualization. We will also provide certain tips for enhancing graphics using MATLAB. In this article, we will see how subscript and superscript can be added into titles, and axis labels of the plot.
Plot command allow the use of underscore '_' and cap '^' to be used as subscript and superscript command, respectively. This way, any sumbol followed by underscore and cap symbol will be treated as subscript and superscript, respectively, and MATLAB will write the texts accordingly. Try executing following MATLAB script into your MATLAB workspace to ge the fill of how these underscore and cap symbols work with title and labeling commands of MATLAB.
load iris.dat; %Loads iris.dat data file into workspace
%Data will be loaded into variable named iris which is of the dimension 150*5.
%The following script will plot first column against second column and then give
%appropriate titles and labels.
plot(iris(:,1),iris(:,2),'b*'); %Plot of first column versus second column.
%'b*' indicates blue colored plot with '*' as markers for each point on the plot.
title('Plot of X_1 versus X_2'); %Write title
xlabel('X_1: 1^s^t column of iris.dat'); %Write label for x-axis
ylabel('X_2: 2^n^d column of iris.dat'); %Write label for y-axis
Execution of the script given above generates following plot in graphic window.
Observe the title, x-label, and y-label. Underscore and cap symbols generated text with subscript and superscript.