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?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ernest Mares
le 27 Déc 2017
Commenté : Ernest Mares
le 28 Déc 2017
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 commentaires
Réponse acceptée
Walter Roberson
le 28 Déc 2017
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 commentaires
Walter Roberson
le 28 Déc 2017
"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.
Plus de réponses (1)
Image Analyst
le 27 Déc 2017
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 commentaire
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!