Borrar filtros
Borrar filtros

Using a pushbutton to show that I have selected the right radiobutton

1 visualización (últimos 30 días)
I have code that does the following:
  1. Uses uipickfile to get a file name
  2. Reads the selected file to get the data.
  3. Stops running at this time to display a uipanel button group (previously invisible) with the possible sample rates FOR THIS FILE. Naturally, with these groups one button is already selected, which has the default sample rate. Unfortunately the sample rate not included in the file.
I would like to either (a) associate a "Done" or "OK" button with the uipanel to say, after the right sample rate is selected, that it's OK to go on, or (b) tell things to proceed after either the default OR another sample rate is selected. Then, I can go ahead and Plot Data (with the right time scale).
This seemed to jump ahead and not let the selection change occur.
Thanks in advance!
Doug Anderson
Oh... the code for what I tried to to with Zheng's suggestions:
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% When pushed,
% set(handles.pushbutton10,'Visible','off');
switch get(get(handles.uipanel2,'SelectedObject'),'Tag') % Get Tag of selected object.
case 'sr_1024_radiobutton'
handles.sample_rate = 1024;
case 'sr_2048_radiobutton'
handles.sample_rate = 2048;
case 'sr_4096_radiobutton'
handles.sample_rate = 4096;
case 'sr_8000_radiobutton'
handles.sample_rate = 8000;
  3 comentarios
Benjamin Avants
Benjamin Avants el 1 de Mayo de 2014
It sounds like you have one button that lets you select a file and read its contents. It then saves the data to the handles structure and sets the radio buttons to visible on. This function should end here.
Then your second button, when pressed, reads the state of the radio buttons and sets a plotting parameter before enabling your plot button.
You plot button then reads the data and parameter from the handles structure and plots the data.
Is this what you're doing? If so, the second button's callback will not run until the button is pressed or its called directly by your code.
Douglas Anderson
Douglas Anderson el 1 de Mayo de 2014
Yes, Benjamin.
I am wondering how the button reads the state of the radio buttons. Is the "SelectionChangeFcn" kept separate from the second button?

Iniciar sesión para comentar.

Respuesta aceptada

Benjamin Avants
Benjamin Avants el 2 de Mayo de 2014
When you place radio buttons in a button group panel, the panel disables the radio buttons' callback functions and replaces them with the panel's SelectionChangeFcn.
In your case, you can do away with your second button entirely and don't need to define a SelectionChangeFcn for the button group panel. Even without defining that function, the button group panel will allow only one radio button to be selected at a time and will update the SelectedObject property every time a new radio button is selected.
You can use your third button to read the SelectedObject property, determine which radio button is selected, and to plot your data.
The SelectedObject property is a property of the button group panel. The switch case in your code should properly identify the button, as long as the four radio buttons have the correct tag and no other buttons (of any sort) are located within the button group panel.
I think your issue was that your first button included the code to plot your data and needed to wait on the selection. Personally, I would move the plotting function to the Callback of the third button. You can also use the uiwait() function to pause the code for the first button until the third button determines the appropriate sample rate and calls uiresume().
To be clear about which button is which:
The first button is the one that loads the file. The second button checks the sampling rate selected via radio button (if it is used). The third button triggers the plot.
Comment on my answer if you need clarification or have questions. I'll check it periodically.

Más respuestas (0)


Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.


Community Treasure Hunt

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

Start Hunting!

Translated by