Effacer les filtres
Effacer les filtres

Switch and Case using radio buttons

12 vues (au cours des 30 derniers jours)
Darya Zheleznyakova
Darya Zheleznyakova le 3 Nov 2021
Modifié(e) : Chris le 3 Nov 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

Réponse acceptée

Chris
Chris le 3 Nov 2021
Modifié(e) : Chris le 3 Nov 2021
The tag is a string (technically a char vector). Include the quotes.
case 'b1'
and
case 'b2'

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by