Info

This question is closed. Reopen it to edit or answer.

Variable sharing in GUI functions..

1 view (last 30 days)
Edmund Paul Malinowski
Edmund Paul Malinowski on 18 Nov 2015
Closed: MATLAB Answer Bot on 20 Aug 2021
Hey all,
As i get further into my program i'm designing a GUI which is now done but i'm starting to code the various components and running into some issues..
One section of the gui is a buttongroup consisting of a pop-up menu, 3 radio buttons and a push button. As you you can see in the code below, i've set up a variable (FiltX) to take a value dependent on the radio button selected and for the push button (which will perform some function) i want to read what the FiltX variable is and action something dependent on that value but i get errors.
Here is my code so far: (i'm using msgboxs only to simply show me if things are working)
% **********************************************
% OPTION BUTTONS SELECTION..
% **********************************************
% --- Executes when selected object is changed in uibuttongroup1.
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
% CHECK WHICH RADIO BUTTON IS SELECTED..
switch get(eventdata.NewValue,'Tag');
case 'OptUNFT'
FiltX = 1;
msgbox({'UNFILTERED NOTE..', num2str(FiltX)});
case 'OptISOLATE'
FiltX = 2;
msgbox({'ISOLATE NOTE..', num2str(FiltX)});
case 'OptFTNT'
FiltX = 3;
msgbox({'FILTER THE NOTE..', num2str(FiltX)});
end
% END SWITCH..
% **********************************************
% APPLY FILTER BUTTON..
% **********************************************
% --- Executes on button press in btAPLLYFT.
function btAPLLYFT_Callback(hObject, eventdata, handles)
switch FiltX; % VARIABLE FROM RADIO BUTTON SELECTION..
case 1
msgbox('You chose to play the original');
case 2
msgbox('You chose to isolate');
case 3
msgbox('You chose to filter');
end
% END SWITCH..
Am i right in assuming its because the FiltX variable is local and not global? If not, what could be causing the issue and whats the best method to check things like variables or values from other functions like this?
Here's what the command window kicks out:
Undefined function or variable 'FiltX'.
Error in EPM_gui_form>btAPLLYFT_Callback (line 180)
switch FiltX;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in EPM_gui_form (line 36)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)EPM_gui_form('btAPLLYFT_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
Thanks,
Paul..

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!