Anda di halaman 1dari 9

PERTEMUAN KE 10

BAHASA
PEMROGAMAN
SELEKSI DAN PENGULANGAN

Octavina Rizky Utami Putri, M.Pd


PERNYATAAN SELEKSI (if…else…end)

s=str2num(SISI);
if s>0
V=s*s*s;
set(handles.edit2,'string',V);
else
set(handles.edit2,'string','SISI > 0');
end
PERNYATAAN SELEKSI (if…elseif…else…end)

bilangan=get(handles.edit1,'string');
bil=str2num(bilangan);
if bil>0
set(handles.edit2,'string','BILANGAN POSITIF');
elseif bil==0
set(handles.edit2,'string','BILANGAN NOL');
else
set(handles.edit2,'string','BILANGAN NEGATIF');
end
LATIHAN

Buat tampilan seperti di


samping dengan
komponen:
2 static text
3 edit text
1 push button
4 radio button
1 button group
SCRIPT
BUTTON GROUP (PILIHAN) PUSH BUTTON (HASIL)
Klik kanan/View Callback/ Klik kanan/View Callback/
SelectionChangeFcn Callback
function function pushbutton1_Callback(hObject,
uipanel1_SelectionChangeFcn(hObject, eventdata, handles)
eventdata, handles) bil1=get(handles.edit1,'string');
pilih=get(eventdata.NewValue,'Tag'); bil2=get(handles.edit2,'string');
switch pilih b1=str2num(bil1);
case 'radiobutton1' b2=str2num(bil2);
set(handles.text2,'string','+'); tanda=get(handles.text2,'string');
case 'radiobutton2' if tanda=='+'
set(handles.text2,'string','-'); hasil=b1+b2;
case 'radiobutton3' elseif tanda=='-'
set(handles.text2,'string',’x'); hasil=b1-b2;
case 'radiobutton4' elseif tanda==‘x'
set(handles.text2,'string',’:') hasil=b1*b2;
end else
hasil=b1/b2;
end
set(handles.edit3,'string',hasil);
HASIL PROGRAM KALKULATOR
PENGULANGAN

Buat tampilan seperti di


samping dengan
komponen:
2 static text
3 edit text
2 push button
SCRIPT
PUSH BUTTON (BARISAN) PUSH BUTTON (DERET)
Klik kanan/View Callback/Callback Klik kanan/View Callback/Callback
function pushbutton1_Callback(hObject, function pushbutton2_Callback(hObject,
eventdata, handles) eventdata, handles)
N=get(handles.edit1,'string'); suku=get(handles.edit1,'string');
n=str2num(N); n=str2num(suku);
Un=[]; a=0;
for i=1:n for i=1:n
if i==1 a=a+i;
Un=[num2str(i)]; end
else set(handles.edit3,'string’,a);
Un=[Un ',' num2str(i)];
end Un=0
end i=1 --- Un=0+1=1
set(handles.edit2,'string’,Un); i=2 --- Un=1+2=3
i=3---Un=3+3=6
i=4---Un=6+4=10
HASIL PROGRAM BARISAN DAN DERET