Professional Documents
Culture Documents
Well, ini hanyalah artikel untuk membuat GUI Matlab yang bisa digunakan sebagai media sketch. Memang tidak profesional, tapi code atau program di dalamnya bisa anda kembangkan menjadi program yang lebih profesional pada aplikasi-aplikasi khusus yang anda inginkan. Tidak ada teori khusus yang perlu diterangkan, karena fungsi-fungsi di dalamnya adalah buatan kita sendiri. Instruksinya pun tidak terlalu sulit. Perhatikan tampilan di bawah ini
Program ini merupakan demo untuk memanfaatkan matlab secara interaktif. Kita bisa memilih warna yang diinginkan lalu dijadikan untuk menggambar kurva pada bidang gambar. Ini hanyalah demo version dari saya, sehingga tidak profesional. Ada beberapa bagian yang saya ambil dari sebuah website yang bagus. Saya terinspirasi dari code yang telah dibuat olehnya. Saya jadikan referensi pada bagian akhir dari artikel ini. Bila program dijalankan, maka akan dihasilkan:
janshendry@gmail.com
Page 1
function callme(warna) global P; global wrn; switch warna case 1 wrn='r'; % merah case 2 wrn='k'; % hitam case 3 wrn='b'; % biru case 4
janshendry@gmail.com
Page 2
% magenta end P=get_pencil_curve(); function P = get_pencil_curve() global p; axis manual; set(gcf,'windowbuttondownfcn',@ondown); set(gcf,'keypressfcn', @onkeypress); P = []; p = []; function ondown(src,ev) set(gcf,'windowbuttonmotionfcn', @ondrag); set(gcf,'windowbuttonupfcn', @onup); append_current_point(); function ondrag(src,ev) append_current_point(); function onup(src,ev) finish(); %% function append_current_point() global P; global p; global wrn; try cp = get(gca,'currentpoint'); P = [P;cp(1,:)]; if isempty(p) % init plot hold on; p = plot(P(:,1),P(:,2),wrn); hold off; else % update plot set(p,'Xdata',P(:,1),'Ydata',P(:,2)); end catch end %% function finish() global done; done = true; set(gcf,'windowbuttonmotionfcn',''); set(gcf,'windowbuttonupfcn',''); set(gcf,'windowbuttondownfcn','');
janshendry@gmail.com
Page 3
%%
% --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text2. function text2_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=2; callme(warna); % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text3. function text3_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=3; callme(warna);
% --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text4. function text4_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=4; callme(warna);
% --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text5. function text5_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=5; callme(warna);
% --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text6. function text6_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=6; callme(warna);
% --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over text7.
janshendry@gmail.com
Page 4
function text7_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to text7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % axes(handles.axes1); warna=7; callme(warna);
Anda bisa melihat sendiri bahwa program ini cukup mudah untuk dipahami... (entah icon smiley ini artinya mengejek atau menyemangati, entah...)
janshendry@gmail.com
Page 5