Experiment window run in the background

Hello, I builled an visual experiment, and every thing is working fine except one important thing - I want that the participant will press the Spcabar key in part of the trials; The problem is that the experiment window keep exit each time I press on the spacebar key, and continue running in the background... (if I go back to the experiment window it's still runnung but again exit from this window). It's write to me this error:
"Error using matlab.ui.Figure/get Invalid or deleted object."
"Error in TwoBack_finalll (line 74) h_but = get(hf,'CurrentCharacter')";
what this means? in other experiment code this function work excelent... :( and what should I do about it??
Thank you, Rotem.

Réponses (3)

Walter Roberson
Walter Roberson le 6 Mar 2018

0 votes

I suspect that you are trying to get the current character of an axes but I suspect that you are using imshow. imshow tends to delete the axes.
Source code would help.
Rotem Maymon
Rotem Maymon le 6 Mar 2018
Modifié(e) : Walter Roberson le 6 Mar 2018
Hello,
I'm not using imshow... here his my code - if you can see something wrong it's would be great... thank you!
clear all
clc
hf=figure('Toolbar','none','Menubar','none','NumberTitle','off',...
'Units','normalized','position',[0 0 1 1],'Color',[1 1 1]);
fig_text1 = text(0.4, 0.8, 'Instructions');
fig_text2 = text(0.3, 0.7, 'In this experience you will see a sequence of letters');
fig_text3 = text(0.2, 0.6, 'Press the SPACE bar if the letter you see is similar to the one you saw TWO triels before');
fig_text4 = text(0.33, 0.4, 'Press any key when you are ready to start');
axis off
waitforbuttonpress
close(hf);
NumberOfTrails = 100;
NumberOfResponses = NumberOfTrails;
NumberOfTwoSteps = 20;
Letters = ['A' 'B' 'C' 'D' 'E' 'F' 'G' 'H' 'I' 'J'];
VisualLetters = [];
IsTwoStep = ['0', '0'];
OneStepBack = Letters(end, randperm(size(Letters, 2), 1));
TwoStepBack = Letters(end, randperm(size(Letters, 2), 1));
VisualLetters{1} = OneStepBack;
VisualLetters{2} = TwoStepBack;
for counter = 3:NumberOfTrails
Random_number = rand(1,1);
PercentageOfTrailsLeft = NumberOfTwoSteps / NumberOfTrails;
if(PercentageOfTrailsLeft > Random_number)
IsTwoStep(counter) = '1';
NumberOfTwoSteps = NumberOfTwoSteps - 1;
CurrentStep = TwoStepBack;
VisualLetters(counter) = cellstr(CurrentStep);
TwoStepBack = OneStepBack;
OneStepBack = CurrentStep;
else
IsTwoStep(counter) = '0';
CurrentStep = Letters(end, randperm(size(Letters, 2), 1));
while(CurrentStep == TwoStepBack)
CurrentStep = Letters(end, randperm(size(Letters, 2), 1));
end
VisualLetters(counter) = cellstr(CurrentStep);
TwoStepBack = OneStepBack;
OneStepBack = CurrentStep;
end
NumberOfTrails = NumberOfTrails - 1;
end
Responses = NaN(NumberOfResponses, 4);
hf=figure('Toolbar','none','Menubar','none','NumberTitle','off',...
'Units','normalized','position',[0 0 1 1],'Color',[1 1 1]);
for Respone = 1:NumberOfResponses
tic;
axis off;
text(0.5,0.5,VisualLetters(Respone));
pause (750/1000); %750 ms
clf;
h_but = get(hf,'CurrentCharacter');
ReactionTime = toc;
Responses(Respone, 2) = VisualLetters{Respone} - 64;
Responses(Respone, 3) = IsTwoStep(Respone) - 48;
if ReactionTime < 0.75
Responses(Respone, 4) = ReactionTime;
end
if Respone > 2
if IsTwoStep(Respone) %if we got a twoStep
if toc <0.75 %if we get a him to react show YES
hold on;
text(0.5, 0.4, 'YES','Color','green','FontSize', 14);
hold off;
else %If not show NO
hold on;
text(0.5, 0.4, 'No','Color','red','FontSize', 14);
hold off;
end
%if it is not a two step and he prssed
elseif isnan(Responses(Respone, 4)) && not(isTwoStep(Resone))
hold on;
text(0.5, 0.4, 'No','Color','red','FontSize', 14);
hold off;
end
end
pause (50/1000);
if isnan(Responses(Respone, 4))
Responses(Respone, 1) = 0;
else
Responses(Respone, 1) = 1;
end
clf(hf);
end
close(hf)
Rotem Maymon
Rotem Maymon le 7 Mar 2018

0 votes

Hello, Thank you. I've read this responses, and it's no it... :(
Have a good day.

1 commentaire

Walter Roberson
Walter Roberson le 7 Mar 2018
Please post the modified version of your code that takes care to parent every graphics operation. (No point in my duplicating that effort.)

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by