Switch and Case using radio buttons

12 次查看(过去 30 天)
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

采纳的回答

Chris
Chris 2021-11-3
编辑:Chris 2021-11-3
The tag is a string (technically a char vector). Include the quotes.
case 'b1'
and
case 'b2'

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by