2014-09-22 36 views
3

我想用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}); 

ADDED:

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 

如果有人能告诉我问题是什么,那会很好。

+0

你介意给我们展示'show_text'函数里有什么,它是一个自定义函数吗? – 2014-09-22 13:54:32

+0

哎呀,忘了包括!只需添加它 – Alex 2014-09-22 13:55:15

+0

如果需要,我可以包含实际脚本的链接 – Alex 2014-09-22 14:00:55

回答

1

,如果你抵消show_text功能这样的height变量通过一个更大的任意因素会发生什么:

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

而不是1.1?或者尝试2

+0

非常感谢! – Alex 2014-09-22 14:05:03

+1

@Alex你很受欢迎,那很简单:-) – 2014-09-22 14:05:42

1

不是直接回答你的问题,但我强烈建议PsychToolbox这... 存在诸多问题与使用实验MATLAB的身影......

您所描述的问题仅仅是一个很多,这就是为什么PsychToolbox,Cogent等被编写出来的原因 - 它们确实使编写这类任务变得更加容易。