Passing gui input variables to mfile to run but the input variables arent passing, how do i set them as handles to use in the mfile i want to run?

3 ビュー (過去 30 日間)
Ive been using an mfile for a visual stimulation paradigm and i decided to create a gui to input variables to the mfile so the stimulation can run. The input variables however are not passing from the gui to the mfile when I run the paradigm.
% --- Executes on button press in StimulationVisual.
function StimulationVisual_Callback(hObject, eventdata, handles)
% hObject handle to StimulationVisual (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f_stim_vis = str2double(get(handles.f_stim_vis,'String'));
totalTime_vis = str2double(get(handles.totalTime_vis,'String'));
r_interval_vis = str2double(get(handles.r_interval_vis,'String'));
s_interval_vis = str2double(get(handles.s_interval_vis,'String'));
set(handles.f_stim_vis,'String',f_stim_vis);
set(handles.totalTime_vis,'String',totalTime_vis);
set(handles.r_interval_vis,'String',r_interval_vis);
set(handles.s_interval_vis,'String',s_interval_vis);
save('Visual_Stimulus','f_stim_vis','totalTime_vis','r_interval_vis','s_interval_vis');
run Visual_Stimulus
  5 件のコメント
Ernest Mares
Ernest Mares 2017 年 12 月 27 日
Visual_Stimulus.mat,sorry on my part I forgot to capitalize
Ernest Mares
Ernest Mares 2017 年 12 月 28 日
I also added the main mfile Visual_Stimulus.m below if you wanted to look at the mfile which runs in the call back.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2017 年 12 月 28 日
Your code does not load() from Visual_Stimulus.mat or from anywhere else. Instead it has
totalTime_vis = 20; %total recording time in seconds
r_interval_vis = 5; %resting block in seconds
s_interval_vis = 5 ; %stimulation block in seconds
which assigns constant values to those parameters.
You should rewrite as a function that accepts those as parameters. Change
save('Visual_Stimulus','f_stim_vis','totalTime_vis','r_interval_vis','s_interval_vis');
run Visual_Stimulus
to
Visual_Stimulus(f_stim_vis, totalTime_vis, r_interval_vis, s_interval_vis)
and at the very top of Visual_Stimulus.m put in
function Visual_Stimulus(f_stim_vis, totalTime_vis, r_interval_vis, s_interval_vis)
if ~exist('f_stim_vis', 'var')
f_stim_vis = 1;
end
if ~exist('totalTime_vis', 'var')
totalTime_vis = 20;
end
if ~exist('r_interval_vis', 'var')
r_interval_vis = 5;
end
if ~exist('s_interval_vis', 'var')
s_interval_vis = 5;
end
and delete the lines
f_stim_vis=1; %alternating frequency in Hz
and
totalTime_vis = 20; %total recording time in seconds
r_interval_vis = 5; %resting block in seconds
s_interval_vis = 5 ; %stimulation block in seconds
With these changes, the code would continue to do what it already does if the user did not pass anything to Visual_Stimulus, but if someone does pass parameters then the parameters would override the default values.
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 12 月 28 日
"How would I start in making a function for the Visual_Stimulus mfile?"
At the very top of Visual_Stimulus.m put in
function Visual_Stimulus(f_stim_vis, totalTime_vis, r_interval_vis, s_interval_vis)
and the other lines that I gave you. I told you the exact changes that need to be made to your file.
Ernest Mares
Ernest Mares 2017 年 12 月 28 日
Yes, it is working now, Thank You Very MMuch

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 12 月 27 日
Please attach the source code for the script "Visual_Stimulus.m" so we can verify that it actually calls
s = load('Visual_Stimulus.mat');
It could be that Visual_Stimulus.m script never even reads in the .mat file.
Maybe also get rid of the run command and just have the m-file name on it's own line.
  1 件のコメント
Ernest Mares
Ernest Mares 2017 年 12 月 28 日
編集済み: Ernest Mares 2017 年 12 月 28 日
This is the mfile Visual_Stimulus, I know it calls back to it since it runs the paradigm, but it just doesnt apply the input from the gui to the mfile.
%Checkerboard Pattern Stimulus-Reversing
sca; %clear screen
% ard = arduino ('com5', 'uno');
rng('shuffle');
PsychDefaultSetup(2); %default settings
screens = Screen('Screens'); %identify # of screens, default screen is 0
screenNumber = max(screens); %select screen to use
white = WhiteIndex(screenNumber); %set white color
black = BlackIndex(screenNumber); %set black color
red = [1 0 0]; %set red color
[window, windowRect] = PsychImaging('OpenWindow', screenNumber,...
black, [], 32, 2, [], [], kPsychNeed32BPCFloat);
ifi = Screen('GetFlipInterval', window); %obtain screen flip interval
% Set the blend function for the screen
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
Screen('TextSize', window, 350);
nominalFrameRate = Screen('NominalFrameRate', window);
presSecs = [sort(repmat(1:5, 1, nominalFrameRate), 'descend') 1];
%Define checkerboard
a=5;
Checkerboard = repmat(eye(2), a, a);
B_Checkerboard = repmat(zeros(2), a, a);
%Create checkerboard textures
CheckerboardTex(1) = Screen('MakeTexture', window, Checkerboard);
CheckerboardTex(2) = Screen('MakeTexture', window, 1-Checkerboard);
[Xcenter, Ycenter] = RectCenter(windowRect); %find window center
b = 1000; %checkerboard dimension
check = [0 0 b b]; %vector of checkerboard square
check_centered = CenterRectOnPointd(check, Xcenter, Ycenter);
%Size of fixation cross arms
fixCrossDimPix = 40;
%Set the fixation cross coordinates in the center
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
%line width of fixation cross
lineWidthPix = 8;
filterMode=0;
for n = 1:length(presSecs)
numberString = num2str(presSecs(n));
DrawFormattedText(window, numberString, (Xcenter-140 ),...,
(Ycenter+125), red);
Screen('Flip', window);
end
% count down duration is about 6 seconds
% Time we want to wait before reversing the contrast of the checkerboard
f_stim_vis=1; %alternating frequency in Hz
checkFlipTimeSecs = 1/f_stim_vis; %duration of each texture
%alternating frequency in frames
checkFlipTimeFrames = round(checkFlipTimeSecs / ifi);
frameCounter = 0; %starting frame counter
waitframes = 1; % Time to wait in frames for a flip
textureCue = [1 2]; % vector to determine texture that will show
vbl = Screen('Flip', window); %vertical blank interval
totalTime_vis = 20; %total recording time in seconds
r_interval_vis = 5; %resting block in seconds
s_interval_vis = 5 ; %stimulation block in seconds
startTime = GetSecs(); %determine loop start time
stopTime = startTime + totalTime_vis; %determine loop stop time
while ~KbCheck && (GetSecs() < stopTime)
startTime_stim = GetSecs(); %set stimulation start time to loop start time
s_duration = startTime_stim + s_interval_vis; %how long stimulation should last
%set rest start time to end of stimulation time
startTime_rest = s_duration;
r_duration = startTime_rest + r_interval_vis;
while ~KbCheck && (GetSecs() <= s_duration) && (GetSecs() < stopTime)
frameCounter = frameCounter + 1; %count frames
% Draw checkerboard to the screen
Screen('DrawTexture', window, CheckerboardTex(textureCue(1)),...
[], check_centered, 0, filterMode);
%Draw fixation cross to the screen
Screen('DrawLines', window, allCoords,...
lineWidthPix, red, [Xcenter Ycenter], 2);
% Flip to the screen
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
% Reverse the texture cue to change the pattern
if frameCounter == checkFlipTimeFrames
%writeDigitalPin(ard, 'D12 ', 1);
%writeDigitalPin(ard, 'D12', 0);
textureCue = fliplr(textureCue);
frameCounter = 0;
end
end
while ~KbCheck && (GetSecs() <= r_duration) && (GetSecs() < stopTime)
%Draw the black texture to the screen
Screen('FillRect', window, black, check_centered);
%Draw fixation cross to the screen
Screen('DrawLines', window, allCoords,...
lineWidthPix, red, [Xcenter Ycenter], 2);
%Flip to the screen
vbl = Screen ('Flip', window);
end
end
stim_end_time = GetSecs();
while ~KbCheck && GetSecs() < (stim_end_time + 5)
Screen('TextSize', window, 70);
Screen('TextFont', window, 'Georgia');
DrawFormattedText(window, 'Thank You For Your Participation',...,
Xcenter*0.50, Ycenter, white);
vbl = Screen ('Flip', window);
end
sca; %clear screen

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by