%% naredba radiobutton clear, clc, close all h0=figure('Position',[200 200 500 400],'Color','b'); h1=uicontrol('Style','radiobutton',... 'Position',[50 250 100 50] ,... 'String','EXIT',... 'callback','close all'); h2=uicontrol('Style','radiobutton',... 'Value', 0,... 'FontSize',12,... 'Position',[50 50 200 50] ,... 'String','Stavi zelenu pozadinu',... 'callback',['if get(h2,''Value'')==1,set(h0,''Color'',''g''), else,',... 'set(h0,''Color'',''b''),end']);%isprobati get(h1) i set(h1) %% naredba popupmenu clear, clc, close all h0=figure('Position',[50 200 300 300],'Color','b'); h1=uicontrol('Style','popupmenu',... 'Position',[50 150 200 50] ,... 'String',{'prvi odabir' 'drugi odabir' 'treci odabir'},... 'callback','sprintf(''odabrali ste %d. odabir'', get(h1, ''Value''))') %'callback','disp([''odabrali ste '', num2str(get(h1, ''Value'')),''. odabir''])'); figure('Position',[400 200 500 400],'Color','g'); x=-2:0.1:10; h3=uicontrol('Style','popupmenu',... 'Position',[50 15 150 15] ,... 'value',2,... 'String',{'sin(x)' 'cos(x)' 'x^2'},... 'callback',['if get(h3,''Value'')==1, f=plot(x,sin(x)),set(h2,''Value'',4),end;',... 'if get(h3,''Value'')==2, f=plot(x,cos(x)),set(h2,''Value'',4),end;',... 'if get(h3,''Value'')==3, f=plot(x,x.^2),set(h2,''Value'',4),end;' ]); %DZ dodajte izbornik u kojem se moze birati dali su tocke spojene ili su %oznacene s tockom, plusem ili kruzicem h2=uicontrol('Style','popupmenu',... 'Position',[250 15 50 15] ,... 'Value',4,... 'String',{'+' '.' 'o','line'},... 'callback',['if get(h2,''Value'')==1, set(f,''Marker'',''+''),set(f,''LineStyle'',''none''),end;',... 'if get(h2,''Value'')==2,set(f,''Marker'',''.''),set(f,''LineStyle'',''none''), end;',... 'if get(h2,''Value'')==3, set(f,''Marker'',''o''),set(f,''LineStyle'',''none''),end;',... 'if get(h2,''Value'')==4, set(f,''Marker'',''none''),set(f,''LineStyle'',''-''),end;']); %% naredba togglebutton clear, clc, close all f0=figure('position',[100 200 200 400],'DeleteFcn','close all'); x=-5:0.1:10; h1=uicontrol('Style','radiobutton',... 'Position',[50 300 50 40] ,... 'String','sin(x)',... 'callback',['if get(h1,''Value'')==1, f1=figure(''position'',[400 410 300 200]);plot(x,sin(x));end;',... 'if get(h1,''Value'')==0, close(f1), end;']); h2=uicontrol('Style','togglebutton',... 'Position',[50 250 50 40] ,... 'String','x^2',... 'callback',['if get(h2,''Value'')==1, f2=figure(''position'',[400 110 300 200]);plot(x,x.^2);end;',... 'if get(h2,''Value'')==0, close(f2), end;' ]); h3=uicontrol('Style','togglebutton',... 'Position',[50 200 50 40] ,... 'String','x^3',... 'callback',['if get(h3,''Value'')==1, f3=figure(''position'',[400 10 300 200]);plot(x,x.^3);end;',... 'if get(h3,''Value'')==0, close(f3), end;',... ]); %% naredba slider clear, clc, close all plot(1,sin(1),'.') axis([0 20 -1 1]) hold on set(gcf,'DefaultUIcontrolUnits','Normalized') slider_f=uicontrol(gcf,'Style','Slider',... 'Min', 0, 'Max', 20.0, 'Value', 1.0,... 'Position', [0.1 0.01 0.83 0.04],... 'CallBack', ['s1value=get(slider_f,''value'');',... 'disp (num2str(s1value));',... 'plot(s1value,sin(s1value),''.'')']) %% primjer: pogadjanje funkcije i naredba msgbox clear, clc, close all %msgbox('Tekst u poruci','Naslov') %msgbox('Tekst u poruci','Naslov','error')%none', 'error', 'help', 'warn', %or 'custom' a=1;b=4; k = a + (b-a).*rand; k=round(k); axis([0 20 -2 2]) hold on switch k case 1, fja='sin(x)'; case 2, fja='cos(x)' ; case 3, fja='cos(x)+sin(x)' ; case 4, fja='sin(2*x)' ; end set(gcf,'DefaultUIcontrolUnits','Normalized') slider_f=uicontrol(gcf,'Style','Slider',... 'Min', 0, 'Max', 20.0, 'Value', 1.0,... 'Position', [0.1 0.01 0.83 0.04],... 'CallBack', ['x=get(slider_f,''value'');s1value=eval(fja),',... 'disp (num2str(s1value));',... 'plot(x,s1value,''o'')']) h1=uicontrol('Style','radiobutton',... 'Position',[0.1 0.95 0.2 0.05] ,... 'String','nacrtaj funkciju',... 'visible', 'off', ... 'callback','x=0:0.01:20;if get(h1,''Value'')==1,;,plot(x,eval(fja)), ylabel(fja);end;'); popm=uicontrol('Style','popupmenu',... 'Position',[0.4 0.95 0.2 0.05] ,... 'Value',4,... 'String',{'sin(x)' 'cos(x)' 'sin(x)+cos(x)','sin(2*x)'},... 'callback',['if get(popm,''Value'')==k, ',... ' msgbox(''TOCNO'',''REZULTAT'',''help'');',... 'else,',... 'msgbox(''NETOCNO'',''REZULTAT'',''error'');end, set(h1,''visible'', ''on'')']); % DZ: dodajte u primjer padajuci meni u kojem se odabire broj dozvoljenih tocaka koje korisnik smije odabrati % kada korisnik odabere broj izmedju 3,6,9,12 ili 15, tada se brise slider te % korisniku preostaje odabrati o kojoj se funkciji radi