Borrar filtros
Borrar filtros

Switch and Case using radio buttons

12 visualizaciones (últimos 30 días)
Darya Zheleznyakova
Darya Zheleznyakova el 3 de Nov. de 2021
Editada: Chris el 3 de Nov. de 2021
Hello! I`m kinda new to radiobuttons and actually matlab, haha.
Problem is: it doesn`t work when I press any of radiobuttons. However, if I write "otherwise" and smth after this - this part works.
Here is the first part of code
hGroup4=uibuttongroup('Units','pixels','Position',[x4,y4,w4,h4]);
rb1=uicontrol(hGroup4,'Style','Radio','String','Periodogram','Position',[5,30,90,20],'Tag','b1');
rb2=uicontrol(hGroup4,'Style','Radio','String','Welch method','Position',[5,10,90,20],'Tag','b2');
set(hGroup4,'SelectedObject',[]);
set(hGroup4,'SelectionChangeFcn',@amadelya1);
and the amadelya1 function
function amadelya1(h,Sel)
%unimportant part
switch get(Sel.NewValue,'Tag')
case b1
window=hamming(length(RR4Hz));
[Pxx,f]=periodogram(RR0,window,nfft,Fs);
plot(f(1:Nf),Pxx(1:Nf));
case b2
Nw=500;
noverlap=100;
window=hamming(Nw);
[Pxx,f]=pwelch(RR0,window,noverlap,nfft,Fs);
plot(f(1:Nf),Pxx(1:Nf));
%otherwise
%anyting here and it works no matter wich button I press
Sorry for messy explanation and my english

Respuesta aceptada

Chris
Chris el 3 de Nov. de 2021
Editada: Chris el 3 de Nov. de 2021
The tag is a string (technically a char vector). Include the quotes.
case 'b1'
and
case 'b2'

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps 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