Question

Here's my GUIDE.

enter image description here

I have two different callbacks for the changing the radio button values (for enabling and disabling the edit boxes) and the clicking of push button.

The problem is that I want to determine which radio button is checked when I press the push button. I tried passing the variable with the codes below (the first three...)

function pbAudio_Callback(hObject, eventdata, handles)
x = getRBValue(rbValue);
if(strcmp(x,'rbRecord'))
    myAudio = wavrecord(get(handles.edtSeconds,'String')*11025,11025);
end
wavplay(myAudio)

function pnlAudio_SelectionChangeFcn(hObject, eventdata, handles)
slctdBtn = get(eventdata.NewValue,'tag')
getRBValue(slctdBtn);
switch slctdBtn
     case 'rbRecord'
        set(handles.edtSeconds,'enable','on');
        set(handles.edtPath,'enable','off');
    case 'rbImport'
        set(handles.edtSeconds,'enable','off');
        set(handles.edtPath,'enable','on');
end

function getRBValue(rbValue1)
rbValue = rbValue1;

Unfortunately, I am receiving the error below.

Undefined function or variable 'rbValue'.

Error in untitled>pbAudio_Callback (line 79)
x = getRBValue(rbValue);

Error in gui_mainfcn (line 96)
    feval(varargin{:});

Error in untitled (line 43)
    gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)untitled('pbAudio_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating uicontrol Callback
Was it helpful?

Solution

the problem is, that you have to get the value of rbValue into your callback. To achieve that, you can use the handles-structure of the GUI. I assume that you are using GUIDE to create the gui.

how to do this-> GUIDE in MATLAB

handles.myVar=123;
%after this dont forget to save it (yes, this is a bit annoying):
guidata(hObject, handles);

later on, within another callback for example, you can find this data within the handles-struct:

handles.myVar

for more information, have a look:

guidata

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top