Switch and Case using radio buttons

11 ビュー (過去 30 日間)
Darya Zheleznyakova
Darya Zheleznyakova 2021 年 11 月 3 日
編集済み: Chris 2021 年 11 月 3 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by