如何防止文字出现在数字上?

时间:2014-09-22 13:42:43

标签: matlab matlab-figure

我正在尝试使用MATLAB设计一个非常简单的Stroop任务,参与者必须决定在屏幕上打印一个单词的颜色。出于某种原因,无论字体有多大或多小,都会剪切单词。

enter image description here

我使用以下代码设置数字大小:

h = figure('Position', [1, 1, 1200, 800]);
set(h, 'NumberTitle', 'off', ...
       'Name', 'Stroop Test', ...
       'Color', 'black', ...
       'MenuBar','none', ...
       'ToolBar', 'none');

为了显示实际的单词刺激,我使用了以下代码:

ht = show_text(h, lang.words(iNoise),...
                'FontSize', 60,...
                'ForegroundColor', lang.colors{iStimul});

增加:

function handle = show_text(parrent, string, varargin)

parpos = get(parrent, 'Position');
pos = [5 round(parpos(4)/2)-30 parpos(3)-10 60];

handle = uicontrol(parrent,...
    'Style','Text',...
    'BackgroundColor', 'black',...
    'ForegroundColor', 'white',...
    'Position', pos,...
    'FontUnits', 'pixels');

if length(varargin) > 0, set(handle, varargin{:}), end;
fontsize = get(handle, 'FontSize');

[outstring,newpos] = textwrap(handle,string);
height = length(outstring) * 1.1 * fontsize;
pos = [5 round(parpos(4)/2)-round(height/2) parpos(3)-10 height];
set(handle,'String',outstring,'Position', pos);
drawnow;

end

如果有人能告诉我问题是什么,那就太好了。

2 个答案:

答案 0 :(得分:1)

不是您问题的直接答案,但我强烈建议PsychToolbox为此... 使用matlab图进行实验有很多问题......

你描述的问题只是众多问题中的一个,这就是为什么写出了PsychToolbox,有说服力等等 - 而且它们确实使得编写这类任务更容易。

答案 1 :(得分:1)

如果您将height函数中的show_text变量偏移更大的任意因子,会发生什么情况:

height = length(outstring) * 1.5 * font size;

而不是1.1?或者尝试2