How to use uisetfont?

조회 수: 3 (최근 30일)
John Doe
John Doe 2020년 7월 6일
답변: Jayanti 2024년 8월 30일
Hello everyone.
How can I use uisetfont command to place texts on a image loaded on a GUIDE axes? How to pass the handle?
Thanks!
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 7월 6일
John - are you passing a handle to the text object that you wish to open the font selection dialog box for? Or are you trying to use uisetfont to write text on the axes? (Which I don't think is the purpose of this function.) Perhaps you should be using text instead.
John Doe
John Doe 2020년 7월 7일
Hello Geoff.
Actually I am trying to write on my image loaded on the axes. The reason I picked uisetfont is to give the user flexibility to choose font type, font size and font style which appears in a box for uisetfont. That's what I am trying to do. But somehow, whenever I am using the function, the texts keep moving away, meaning it's not being written on top of the picture.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jayanti
Jayanti 2024년 8월 30일
To place text on the image loaded into the axes, you can useuisetfont to select font properties, and then placing text on the image at a specified location.
You can start by creating a figure window and an axes component where the image will be displayed. Then create a handle, storing the axes handle. Then you can load your image by passing the handle you created.
hFig = figure();
hAxes = axes('Parent', hFig);
handles = struct();
handles.axes1 = hAxes;
Now since you are facing the issue of text movement you can specify the coordinates where you want to display text using “ginput” which captures click inputs.
Below is the code you can refer to for the same. Here “guidata” will update the handle and “fontProps” is the variable that holds the font properties selected through the font selection dialog box.
function myGui_OpeningFcn(Object, event, handles, varargin)
defaultFont = struct('FontName', 'Helvetica', 'FontSize', 12, 'FontWeight', 'normal');
fontProps = uisetfont(defaultFont, 'Select Font');
if isstruct(fontProps)
title('Click on the image to place the text', 'FontSize', 12, 'Color', 'red');
[x, y] = ginput(1);
textString = 'Text to be displayed';
text('Parent', handles.axes1, 'Position', [x, y], 'String',textString,'FontName', ...
fontProps.FontName, 'FontSize',fontProps.FontSize,'FontWeight',...
fontProps.FontWeight,'Color', 'white');
else
disp('Font selection was canceled');
end
guidata(Object, handles);
end
I am also attaching the documentation link of "uisetfont" for your reference:
This should resolve your issue. Let me know if you have any further queries.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by