Thursday, 10 September 2015

How to add a name to Matlab figure's title bar?

1. How to add a name to the Matlab figure's title bar? For example, Figure 1: Time of the year vs. Temperature.

figNum = 1;
figure(figNum)
set(figNum, 'Name', 'Time of the year vs. Temperature');


Output for this code is shown below:





Thursday, 5 March 2015

How to change default settings for figures in Matlab?

1. Use the following commands


set(0,'DefaultTextFontsize',8, ...
'DefaultTextFontname','Times New Roman', ...
'DefaultTextFontWeight','bold', ...
'DefaultAxesFontsize',8, ...
'DefaultAxesFontname','Times New Roman', ...
'DefaultLineLineWidth', 2);

Wednesday, 11 February 2015

How to reduce the gap (space) between subplots in Matlab?

1. tight_subplot  is a very good function which does exactly the same and gives us access to control the space between subplots.

Example:

figure(140);clf

%Units are normalized to 1. 
gap = [0.005 0.005]; %lower, uppper between subplots
figureMargin_topAndBottom = [.2 .15];
figureMargin_leftAndirght = [.2 .15];


ha = tight_subplot(2,2,gap, figureMargin_topAndBottom, figureMargin_leftAndirght)

corrMs = randn(100);

for ii = 1:1:4

     axes(ha(ii)), % this is important.... this activates that particular subplot
     surf(abs(corrMs));  shading interp
        view(0,0); % viewing from x-dimension (x-z axes)
     if ii > 2
        view(90,0); % just viewing from another dimension (y-z axes)
    end
end


set(ha(2),'ZTickLabel',[]);
set(ha(4),'ZTickLabel',[]);
set(ha(1:2),'YTickLabel',[]);
set(ha(3:4),'XTickLabel',[]);

set(gcf, 'Color', 'w'); % background of the figure, outside the axes

axes(ha(3)); % this activates the axes and lets you add the attributes to that subplot
ylabel('X Data');
zlabel('Z Data');