MATLAB cannot write text on images

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 日

0 投票

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).

カテゴリ

ヘルプ センター および File ExchangeText Data Preparation についてさらに検索

質問済み:

2017 年 1 月 18 日

編集済み:

2017 年 1 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by