MATLAB: How to place a uitable in a subplot (MATLAB R2013a)

MATLABsubplotuitable

I would like to place a uitable so that it fits exactly into one of the subplots in my figure. Is there a way to associate a uitable with a subplot?

Best Answer

There is no way to directly associate a uitable with a subplot, as uitable cannot be children of an axes. However, there is a simple workaround for this which involves saving the properties of the subplot.
The general idea is to create the subplot where you want the uitable to be located. Once the subplot is created, you can save the "Position" property of the subplot. This property contains both the location and the size of the axes. You can also save the units to ensure that the "Position" values are interpreted correctly.
Once these values are saved, you can delete the axes, and create a uitable using the same "Position" and "Unit" properties. This will ensure that the uitable has the same location and size as the subplot axes. For example, please try the following example code.
 
hf = figure;
ha = subplot(2,3,5);
pos = get(ha,'Position');
un = get(ha,'Units');
delete(ha)
ht = uitable('Units',un,'Position',pos)
This will create a uitable exactly where the subplot was first displayed.