MATLAB: How do position coordinates work on a subplot

MATLABplottingsubplot

I have a subplot filled with one video up top and two graphs underneath. In order to get the ratio right I used a subplot(4,4,1:12) for the video, subplot(4,4,13:14) for one graph and subplot(4,4,15:16) for the other. I am now trying to use insertText() and insertShape() to add labels on top of the video but I'm not sure how the position works in those two functions. Can anyone clariffy?

Best Answer

insertText() and insertShape() work with array coordinates, and those are not necessarily the same as axes data coordinates. An array is being written in to, and then in this situation, the array has to be displayed on an axes.
The primary method of displaying an array on an axes is to use image() objects: imagesc() and imshow() both use image() internally. image objects have xdata and ydata properties https://www.mathworks.com/help/matlab/ref/image.html#buqdlnb-x that describe the transformation from array indices to data coordinates. The default mapping is to put the center of the lower left pixel at data coordinates (1,1) and increase by one data unit for each adjacent array coordinate. Other objects in the axes work with data coordinates (except for annotation objects, which are not actually inside the axes.)
It is entirely valid to have an array that is (say) 480 x 640 x 3, and to image() it specifying that the center of the lower left array element is to go at data coordinate (3,10) and that the center of the upper right array element is to go at data coordinate (9.4, 14.4) so that adjacent array elements become 1/100 data units apart, and then to plot(1:15, 10*rand(1,15)) and have the line be drawn across the full image.
Data units in turn get interpreted into physical screen pixels according the the axes Position and Units and whatever containers the axes is nested inside, including the figure position. Typically, if the user grabs the figure and resizes it then nothing needs to change at the lower levels (but the text might start to look bad.)