Cannot terminate the screen with a button

Hi,
I am trying to learn MATLAB on my own and has struggled through with my mac airbook, I have switched to Linux for it and it works fine except one thing that I cannot terminate screen with any button after I opened it. And Idk why. I could terminate it with sca code but I do not want to do it for purposes of next codes. I also try ErrorCathDemo and it show like this;
This is the code I am trying. After it opens grey screen, I am not able to close it :( 
% Clear the workspace and the screen
sca;
close all;
clearvars;

% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);

% Get the screen numbers. This gives us a number for each of the screens
% attached to our computer.
screens = Screen('Screens');

% To draw we select the maximum of these numbers. So in a situation where we
% have two screens attached to our monitor we will draw to the external
% screen.
screenNumber = max(screens);

% Define black and white (white will be 1 and black 0). This is because
% in general luminace values are defined between 0 and 1 with 255 steps in
% between. All values in Psychtoolbox are defined between 0 and 1
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);

% Do a simply calculation to calculate the luminance value for grey. This
% will be half the luminace values for white
grey = white / 2;

% Open an on screen window using PsychImaging and color it grey.
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey);
======

Thanks
HD


Add, e.g. a WaitSecs(2) for 2 second screen open, and then sca again

Also recommended is to wrap all your code in a try-catch block. If things error, the code in the catch block will be run, where you can then put sca to at least kill the screen

On Thu, May 23, 2019 at 9:49 PM 2x34umvpzxcznpgg6tadocppxjo5xonbmz2xeczw@... [PSYCHTOOLBOX] <PSYCHTOOLBOX@yahoogroups.com> wrote:


Hi,
I am trying to learn MATLAB on my own and has struggled through with my mac airbook, I have switched to Linux for it and it works fine except one thing that I cannot terminate screen with any button after I opened it. And Idk why. I could terminate it with sca code but I do not want to do it for purposes of next codes. I also try ErrorCathDemo and it show like this;
This is the code I am trying. After it opens grey screen, I am not able to close it :(
% Clear the workspace and the screen
sca;
close all;
clearvars;

% Here we call some default settings for setting up Psychtoolbox
PsychDefaultSetup(2);

% Get the screen numbers. This gives us a number for each of the screens
% attached to our computer.
screens = Screen('Screens');

% To draw we select the maximum of these numbers. So in a situation where we
% have two screens attached to our monitor we will draw to the external
% screen.
screenNumber = max(screens);

% Define black and white (white will be 1 and black 0). This is because
% in general luminace values are defined between 0 and 1 with 255 steps in
% between. All values in Psychtoolbox are defined between 0 and 1
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);

% Do a simply calculation to calculate the luminance value for grey. This
% will be half the luminace values for white
grey = white / 2;

% Open an on screen window using PsychImaging and color it grey.
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey);
======

Thanks
HD




On Thu, May 23, 2019 at 9:52 PM
2x34umvpzxcznpgg6tadocppxjo5xonbmz2xeczw@... [PSYCHTOOLBOX]
<PSYCHTOOLBOX@yahoogroups.com> wrote:
> Hi,
> I am trying to learn MATLAB on my own and has struggled through with my mac airbook, I have switched to Linux for it and it works fine except one thing that I cannot terminate screen with any button after I opened it. And Idk why. I could terminate it

-> Congratulations for switching to Linux. Good for you!

with sca code but I do not want to do it for purposes of next codes. I
also try ErrorCathDemo and it show like this;
> This is the code I am trying. After it opens grey screen, I am not able to close it :(
>

Can you clarify why you don't want to use sca? Because in your
example, obviously if you don't add a command to close the onscreen
window, it will not magically close by itself. How would the poor
thing know you want it to close without a command to do so? There's
Screen('Close', window) if you just want to close that specific
window, or Screen('CloseAll') if you want to close all windows. Both
close one or all windows, without doing all the other cleanup work of
sca() - assuming you want to prevent some of the cleanup work for
happening?

Other than that, what Diederick recommends.
-mario

> % Clear the workspace and the screen
> sca;
> close all;
> clearvars;
>
> % Here we call some default settings for setting up Psychtoolbox
> PsychDefaultSetup(2);
>
> % Get the screen numbers. This gives us a number for each of the screens
> % attached to our computer.
> screens = Screen('Screens');
>
> % To draw we select the maximum of these numbers. So in a situation where we
> % have two screens attached to our monitor we will draw to the external
> % screen.
> screenNumber = max(screens);
>
> % Define black and white (white will be 1 and black 0). This is because
> % in general luminace values are defined between 0 and 1 with 255 steps in
> % between. All values in Psychtoolbox are defined between 0 and 1
> white = WhiteIndex(screenNumber);
> black = BlackIndex(screenNumber);
>
> % Do a simply calculation to calculate the luminance value for grey. This
> % will be half the luminace values for white
> grey = white / 2;
>
> % Open an on screen window using PsychImaging and color it grey.
> [window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey);
>
> ======
>
> Thanks
> HD
>
>
>