Names of MATLAB Subtype Headers and Axes

I have the following script to end up building a 4 by 2 substring:

files = getAllFiles('preliminaries'); n = size(files); cases = cell(1, n); m = cell(1, n); for i = 1:1:n S = load(files{i}); cases{i} = retransmission_distribution(S); c = size(cases{i}); m{1,i} = cell(1, c(2)); %figure(i); str_size = size(files{i}); title_str = files{i}(5:str_size(2) - 4); title_str = strrep(title_str, '_', ' '); %title(title_str); for j = 1:1:c(2) [x, y] = hist(cases{i}{1,j}); m{1,i}{1,j} = [x; int32(y)]; % subplot(4, 2, j); % xlabel('Number of Retransmissions'); % ylabel('Number of Occurrences'); % bar(y, x, 'histc'); end end 

However, if I have the current order of the sequence of commands, even with no comments, the header and axis labels were present for a while before erasing. I want the figure to have its own caption, with each subtitle having its own axis labels. What is the easiest way to fix this?

+7
matlab plot label figure
source share
4 answers

For axis axis labels, it is true that they should be placed after the BAR is called. This will take care of a single axis problem. However, you will probably notice that your Y axis labels, in particular, can be written on top of each other if they are too long. You have several options to fix this. First, you can adjust the font size in your call to YLABEL :

 ylabel('Number of Occurrences','FontSize',7); 

Secondly, you can convert one long label to a multi-line label using an array of row cells instead of a single row

 ylabel({'Number of' 'Occurrences'}); 

To add a caption to the whole picture, the best option is perhaps to create a static UICONTROL text object and adjust its position, so it is located next to the top of the figure. First, you can get the size and position of the shape to help place the text box on the top and center:

 figureSize = get(gcf,'Position'); uicontrol('Style','text',... 'String','My title',... 'Position',[(figureSize(3)-100)/2 figureSize(4)-25 100 25],... 'BackgroundColor',get(gcf,'Color')); 

This will create a static text box with a width of 100 pixels and a height of 25 pixels, located in the center of the upper part of the picture and with the same background color as the figure.

+8
source share

Here's the solution I saw on the MATLAB exchange forum a while ago, and it worked pretty well for me. After creating the picture, execute the following sequence of commands:

 set(gcf,'NextPlot','add'); axes; h = title('Intended Figure Title'); set(gca,'Visible','off'); set(h,'Visible','on'); 
+4
source share

suptitle is what you are looking for.

It puts the name in the center above all the graphs.

 SUPTITLE Puts a title above all subplots. SUPTITLE('text') adds text to the top of the figure above all subplots (a "super title"). Use this function after all subplot commands. 
+4
source share

As far as I know, the title function places text relative to a set of axes, so there is no such thing as a shape name. Possible workarounds include using the title only for a well-placed subheading (for example, the first or middle from the top row) or manually creating a set of axes in the place where you want to get the name.

For axis labels, try placing label commands after the panel command.

+2
source share

All Articles