alternative approach of "insertObjectAnnotation" function
38 views (last 30 days)
Show older comments
Yu Li
on 9 Sep 2025 at 0:53
Commented: Yu Li
on 9 Sep 2025 at 12:41
Hi:
I'm doing some stock analysis, I use Matlab to plot 4 different figures and connect them together. then I would like to add a customized description.
I found in order to add the text on an image I need to buy computer vision toolbox... so come here to ask if there is any alternative approach to add cusotmized text in the figure attached.
Thanks!
Yu

0 Comments
Accepted Answer
cui,xingxing
on 9 Sep 2025 at 1:37
Edited: cui,xingxing
on 9 Sep 2025 at 1:49
You can use the title built-in function(only require MATLAB) to set a custom title — it is designed for graphics objects — instead of using insertObjectAnnotation, which directly adds a text-shaped annotation onto the image and returns the resulting RGB image array.
Additionally, if you want to customize the title position, you can also try the text built-in function(only require MATLAB) to place a custom title at specified coordinates.
Example:
figure;
t = tiledlayout(2,2);
% Tile 1
nexttile
plot(rand(1,20))
title('Your Title 1')
% Tile 2
nexttile
plot(rand(1,20))
title('Your Title 2')
% Tile 3
nexttile
plot(rand(1,20))
title('Your Title 3')
% Tile 4
nexttile
plot(rand(1,20))
title('Your Title 4')
title(t,"customized text here",FontSize=20,FontWeight="bold")
2 Comments
cui,xingxing
on 9 Sep 2025 at 3:23
Do not use subplot; it is an outdated function. Please use tiledlayout instead — it lets you control the spacing between different axes(TileSpacing).
More Answers (1)
Walter Roberson
on 9 Sep 2025 at 5:00
insertObjectAnnotation from the Computer Vision Toolbox is used to insert text into an array, retaining full resolution of the array. The resulting array is suitable for writing out at full resolution to file using imwrite() or similar. There is no need to display the image at any point when using this function.
You can also choose to display the image and use functions such as title() and text(). These work well if your final destination is the displayed image.
However, if your final destination is writing to an image file, then using functions such as title() and text() requires that you capture plotted information using getframe . getframe() works at whatever resolution the axes were displayed at, which is typically either larger or smaller than the original image resolution. getframe() is not suited at all for retaining the original image resolution.
If you need to retain the original image resolution, then the tools of the Computer Vision Toolbox are the only supported functions.
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!