# Is there a way to measure interletter spacing for Fixed Width font in MATLAB?

조회 수: 7(최근 30일)
Kathleen Kay Amora 2021년 10월 27일
댓글: Scott MacKenzie 2021년 10월 28일
Hello, I am trying to calculate the physical characteristics of the text we plan to use for our experiment. Now to finalize this, I need to know these following information PER character: size of letters, interletter spacing in cm and degrees of visual angle per font size (font size 16, 18, 20 and 22). I am relatively a newbie in MATLAB and I cannot find a function that could work. I am using Fixed Width font style.
I would appreciate any help I could get.
Thank you.

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

### 답변(2개)

J. Alex Lee 2021년 10월 27일
I have no idea what you mean by "visual angle per font size", but I know of one way:
lbl = uicontrol("Style","text","String","X","FontName","courier")
This creates a text label on a figure, and once it is rendered, you can query its "Extent" property:
lbl.Extent
which is a [position,extent] vector, so the 3rd element is the width.
So playing around with it can give hints about how the UI system will position characters
lbl = uicontrol("Style","text","String","X","FontName","courier").Extent
lbl = uicontrol("Style","text","String","XX","FontName","courier").Extent
lbl = uicontrol("Style","text","String","XX X","FontName","courier").Extent
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

Scott MacKenzie 2021년 10월 27일
편집: Scott MacKenzie 2021년 10월 27일
For text fonts, 1 pt = 1/72 inches. So, if you set the font size of the text to, say, 36 pt., the character height will be 1/2 inch or 1.27 cm. I suggest you do some actual measurements to verify and work with those measurements. MATLAB's "extent" property for text includes margins, so I'd be hesitant to use those width and height values.
As for visual angle, that's an arctan calculation. You need the size of the characters and the distance of the participant's eye from the display. For example, the visual angle in degrees for a character 1 cm in size viewed from a distance of 65 cm is
atand(1/65)
ans = 0.8814
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
Scott MacKenzie 2021년 10월 28일
@Kathleen Kay Amora First, let me apologize for the false starts yesterday. I posted some code, then edited and reposted a few times. Then, I deleted the code as I felt it was heading down the wrong path. Since you've asked, I'll repost the code below. I hope you find it useful.
There are a few challenges in trying to use code to get the measurements you want. Many people's computing environments include different sizes of displays or >1 display, so the 'centimeter' units produced by the code are dubious at best. Plus, the text sizing measurements are for the text plus a margin around the text.
Here's the code. Good luck.
set(0, 'units', 'centimeters');
screenSize = get(0, 'ScreenSize'); % verify with measuring tape
wScreen = screenSize(3);
hScreen = screenSize(4);
txt = 'ABC';
fontSize = 48;
set(gca, 'xlim', [0 1], 'ylim', [0 1]);
t = text(0.5, 0.5, txt, 'FontName', 'fixedwidth', 'FontSize', fontSize, ...
'HorizontalAlignment','center', 'VerticalAlignment','middle', ...
'Margin', 15);
t.Units = 'centimeters';
d = 65; % distance (cm) of participant's eye from display (adjust as needed)
n = length(txt); % number of characters
w = t.Extent(3) / n; % per-character width (Note: includes margin)
h = t.Extent(4) / n; % per-character height (Note: includes margin)
va = atand(w/d); % per-character visual angle (degrees)
s = newline;
s = [s sprintf('%15s: %.1f cm x %.1f cm\n', 'Screen size', wScreen, hScreen)];
s = [s sprintf('%15s: %s\n', 'Text', txt)];
s = [s sprintf('%15s: %d pt\n', 'Font size', fontSize)];
s = [s sprintf('%15s: %.2f cm per character\n', 'Width', w)];
s = [s sprintf('%15s: %.2f cm per character\n', 'Height', h)];
s = [s sprintf('%15s: %.2f degrees per character at d = %d cm\n', 'Visual angle', va, d)];
disp(s);
Screen size: 49.3 cm x 30.8 cm Text: ABC Font size: 48 pt Width: 1.02 cm per character Height: 0.72 cm per character Visual angle: 0.90 degrees per character at d = 65 cm

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

### 범주

Find more on Files and Folders in Help Center and File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by