MATLAB cannot write text on images

5 次查看(过去 30 天)
I have been trying to write text on generated figure using the insertText function. Even when using the following example code given in the Mathworks website:
I = imread('peppers.png');
position = [1 50; 100 50];
value = [555 pi];
RGB = insertText(I,position,value,'AnchorPoint','LeftBottom');
I am still getting errors saying:
cell contents reference from a non-cell array object.
Error in listTrueTypeFonts>createFontInfo (line 93)
if ~ismember(fontNameCell{p},fontList) && ~isempty(fontNameCell{p})
I typed in the following to check system font availability on my MATLAB setup:
listTrueTypeFonts
I still get the same error message. But my Windows 10 installation shows several TrueType fonts installed.

回答(1 个)

Geoff Hayes
Geoff Hayes 2017-1-18
编辑:Geoff Hayes 2017-1-18
Debangshu - according to insertText text input argument, your value should be a text character vector or cell array of text character vectors. I think that the MATLAB example is incorrect and that they are missing a step to convert this to a cell array of strings like
text_str = {'555', num2str(pi)};
or
text_str = cell(1,length(value));
for k=1:length(value)
text_str{k} = num2str(value(k));
end
RGB = insertText(I,position, text_str,'AnchorPoint','LeftBottom');
This is similar to what they did in a previous example (converting the numeric array to a cell string array).

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by