MATLAB: DrawFormattedText error using Psychtoolbox

drawformattedtextMATLABpsychtoolbox

I'm trying to set up a simple test experiment using Psychtoolbox, but I can't even get past showing my 3-line instructions on the screen with DrawFormattedText. This is my code:
% Set up the screen
clear all
close all
Screen('Preference','SkipSyncTests',1);
[win,screenRect]=Screen('OpenWindow',0,[127 127 127],[100 100 1000 800]);
% Instructions
tstring=["Blabla.\nBlabla.\nBlabla."];
[nx,ny]=DrawFormattedText(win,tstring,'center','center',[0 0 0]);
Screen('Flip',win)
% Close experiment
pause(3)
sca
However, when I try to run it, I get this error:
Index exceeds the number of array elements (1).
Error in DrawFormattedText (line 276)
tstring = [ tstring(1:min(newlinepos)-1) repchar tstring(min(newlinepos)+2:end)];
Error in Experiment (line 17)
[nx,ny]=DrawFormattedText(win,tstring,'center','center',[0 0 0]);

Best Answer

tstring=["Blabla.\nBlabla.\nBlabla."];
Psychtoolbox was written before string objects existed. You will need to pass a character vector not a string object.
Related Question