Store a variable from a GUI action
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 19 Giu 2015
uicontrol callbacks cannot return a value.
See though
2 Commenti
Walter Roberson
il 19 Giu 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);
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!