Store a variable from a GUI action
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello. I'm designing a GUI for an image processing application. On pushing a button, I need an action to be executed and also a variable to be stored. The exectuted action is uigetfile to obtain the path to a file. The variable is the path to the file so my program accesses that file later. I suppose it is a string(?). I tried getting that variable like I would in a regular function:
function [file_path]=pushbutton1_Callback(hObject, eventdata, handles)
but I suppose that's not the way to do it. I found I should specify the value of a variable when using assignin as:
assignin(WS, name, value)
but how do I specify this if it's not numerical? Thank you
0 commentaires
Réponses (1)
Walter Roberson
le 19 Juin 2015
uicontrol callbacks cannot return a value.
See though
2 commentaires
Walter Roberson
le 19 Juin 2015
t1_path = evalin('base', 't1_path');
But Don't Do That.
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%%Open a dialog box requesting the image file
[img_name, img_path] = uigetfile('*.nii', 'Select the image');
%Concatenate path and name for future reference
img_path_name = fullfile(img_path, img_name);
handles.t1_path = img_path_name;
guidata(hObject, handles);
and
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t1_path = handles.t1_path;
displayDecreaseFA(t1_path);
Voir également
Catégories
En savoir plus sur Entering Commands 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!