how to add another title to a plot with unknown title in matlab

To add another title to a plot in MATLAB, you can use the title function. If the original title is unknown or variable, you can store the original title in a variable and append the new title to it. Here's an example:

main.m
% create some sample data
x = 1:10;
y = rand(1,10);

% plot the data and store the original title
h = plot(x,y);
orig_title = get(gca,'Title').String;

% add a second title 
new_title = 'My New Title';
title([orig_title ' ' new_title]);
237 chars
12 lines

In this example, the get function is used to retrieve the current title string of the plot. This is stored in the variable orig_title. Then, the title function is called again to add the new title, which is appended to the original title with a space in between.

Note that the gca function is used to get the handle to the current axes, which is required for the get function to retrieve the plot title.

related categories

gistlibby LogSnag