Question

I have written code below to plot to graphs in a window using subplot. But for labeling, only first subplot is labeled what should I do? This problem exists for titling, too.

stem(n, h1);
xlabel('n');
ylabel('h1');
subplot(212)
stem(n, h2);
xlabel('n');
ylabel('h2');
Was it helpful?

Solution

In general if you return handles to your figures/axes when you create them, you can tailor each piece by passing that handle as the first argument to a plot modifying function.

So if you did

a1 = subplot(2,1,1);
a2 = subplot(2,1,2);

you could then do

xlabel(a1, 'title here', 'FontSize', 12)
xlabel(a2, 'other title', 'FontWeight', 'bold')

or any other label-specific customizations you want.

OTHER TIPS

To create subplots with individual titles - loop through them:

Titles= {'Title One' 'Title Two'} 

figure;
for i = 1:2;
    subplot(1,2,i);
    plot(x,y(:,i);
    title(Titles(i));
end

Also if you want a main Title and X & Y labels over all the subplots this code is handy: http://www.mathworks.com/matlabcentral/fileexchange/7772-suplabel ...but it takes your code an additional ~13 seconds to run.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top