Membuat GUI di Matlab dengan tombol Load *.MAT

File mat merupakan file hasil olah Matlab sebelumnya (image processing, jaringan syaraf tiruan, dan lain-lain). Biasanya hasil oleh ini disimpan dalam file dengan instruksi save <nama_file> dan diberikan ekstensi oleh matlan mat.

Pertama-tama persiapkan satu folder untuk program yang akan kita buat. File mat harus diletakkan pada folder kerja tersebut (pada matlab diberi istilah current directory). Buat suatu GUI baru dengan nama misalnya ambil_file.

guide

Anda akan melihat pilihan mau buat GUI kosong, GUI yg pernah dibuat, atau sudah bertemplate. Pilih saja yang Blank GUI (Default). Drug toolbox command button berlambang “OK” ke arah lembar kerja GUI. Secara default akan diberi nama Push Button.

Untuk mengedit Push Button, klik ganda tombol itu hingga memunculkan properties. Ganti Push Button dengan isian pada String: Ambil File. Dan nama variabel (pada Matlab diberi nama Tag) isi dengan nama ambil. Tag ini akan menampilkan fungsi ambil di file m matlab.

Simpan GUI anda dan beri nama, misalnya ambil. Matlab akan menciptakan dua file yaitu ambil.fig dan ambil.m fungsinya berturut-turut sebagai GUI dan sebagai script. Secara ajaib, Matlab akan memberikan kode yang siap kita isi di sana. Dengan cara yang sama, buat seperti di bawah ini:

Edit text di sebelah kanan biarkan saja, tidak perlu di utak-atik supaya cepat, dan nama Tag (variabel)-nya edit1. Maksudnya adalah menampilkan nama file yang diambil. Masukan listing seperti berikut ini:

  • [x,y] = uigetfile(‘*.mat’, ‘Mengambil Data’);
  • set(handles.edit1,‘String’,x);
  • y=load(x)
  • net=y.network1

Uigetfile akan mengambil jendela get file dengan ekstensi yang akan ditampilkan *.mat. Pada jendela akan muncul nama jendela ‘Mengambil Data‘. Saya mengambil data saya bernama jst.mat, hasil training JST yang lalu. Instruksi y=load(x) akan mengambil variabel x ke workspace dan net=y.network1 mengambil variabel di y yang isinya hanya jst saya (network1). Jika Anda lihat di command window akan muncul y dan net saya, tentu saja jika Anda tidak memiliki file jst.mat milik saya tidak akan muncul networknya (coba buat sendiri). Silahkan cek apakah file tersebut muncul di sebelah kanan tombol Ambil File (Edit Text).

Sekarang kita coba menyimpan data yang kita barusan ambil (atau mungkin data hasil oleh GUI jika ada). Misal kita akan merename. Isi pada fungsi simpan (awas jangan salah kamar) di m-file pada simpan_Callback.

  • y=load(‘jst.mat’)
  • [nm_file] = uiputfile(‘*.mat’,‘Menyimpan File’);
  • data_file = [nm_file];
  • save(data_file);

Jalankan, Anda akan menampilkan jendela simpan. Bisa Anda tambahkan message jika file telah tersimpan. Di sini kita coba menyimpan y hasil dari loading suatu file (‘jst.mat‘). Dan akan menyimpannya menjadi file lain, misalnya jst2.mat.

Contoh di atas hanya mencoba GUI saja, karena tidak ada yang diolah di sini. Anda bisa menyisipkan fungsi-fungsi ini pada sistem yang anda rancang. Dari pengolahan gambar hingga fungsi-fungsi berat seperti Algoritma Genetik yang saya buat untuk mencari lokasi SPBU yang optimal di Bekasi.

Iklan

26 thoughts on “Membuat GUI di Matlab dengan tombol Load *.MAT”

  1. assalamualaikum pa bagaimana me load hasil training jst .mat yang berisi jaringan net network pa ? saya sudah mencoba tapi gagal dalam men load data neural network net kedalam handels gui terimakasih pa

  2. permisi mau tanya pak, saya sudah bisa membedakan warna dengan output yang sesuai,
    nah saya mau membuat program kemiripan benda dengan warna yang dimiliki
    misalkan ada kualitas cabai merah yang bagus kemudian dijadikan gambar acuan untuk mendeteksi cabai merah yang lainnya gimana ya?
    terimakasih

    1. kalo cuma warna ya pakai image processing aja (imread, dll). cari warna merah yg bagus itu range di angka RGB berapa.
      masalahnya akurat atau tidak kalau cuma warna. setahu saya ada yg neliti jeruk itu selain warna juga kerut di kulitnya.

  3. pak kalu sudh bua gui dan sudah bisa jalan
    lalu di esok harinya dibuka lagi muncul pesan eror seperti berikut maksudnya apa pak

    Attempt to reference field of non-structure array.

    Error in FIGLUASLINGKARAN>edit1_Callback (line 84)
    jari=str2num(get(handles.edit1,’String’));

    Error in gui_mainfcn (line 96)
    feval(varargin{:});

    Error in FIGLUASLINGKARAN (line 42)
    gui_mainfcn(gui_State, varargin{:});

    Error in
    @(hObject,eventdata)FIGLUASLINGKARAN(‘edit1_Callback’,hObject,eventdata,guidata(hObject))

    Error while evaluating uicontrol Callback

  4. Error while evaluating uicontrol Callback

    Error using imread (line 350)
    File “logo.bmp” does not exist.

    Error in manipulgbr>pushbutton1_Callback (line 79)
    I=imread(namafile);set(open.figure1,’CurrentAxes’,open.axes1);

    Error in gui_mainfcn (line 96)
    feval(varargin{:});

    Error in manipulgbr (line 42)
    gui_mainfcn(gui_State, varargin{:});

    Error in
    @(hObject,eventdata)manipulgbr(‘pushbutton1_Callback’,hObject,eventdata,guidata(hObject))

    Error while evaluating uicontrol Callback

      1. function varargout = TUGASMATEMATIKA(varargin)% TUGASMATEMATIKA MATLAB code for TUGASMATEMATIKA.fig%      TUGASMATEMATIKA, by itself, creates a new TUGASMATEMATIKA or raises the existing%      singleton*.%%      H = TUGASMATEMATIKA returns the handle to a new TUGASMATEMATIKA or the handle to%      the existing singleton*.%%      TUGASMATEMATIKA(‘CALLBACK’,hObject,eventData,handles,…) calls the local%      function named CALLBACK in TUGASMATEMATIKA.M with the given input arguments.%%      TUGASMATEMATIKA(‘Property’,’Value’,…) creates a new TUGASMATEMATIKA or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before TUGASMATEMATIKA_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to TUGASMATEMATIKA_OpeningFcn via varargin.%%      *See GUI Options on GUIDE’s Tools menu.  Choose “GUI allows only one%      instance to run (singleton)”.%% See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help TUGASMATEMATIKA % Last Modified by GUIDE v2.5 20-May-2015 09:05:37 % Begin initialization code – DO NOT EDITgui_Singleton = 1;gui_State = struct(‘gui_Name’,       mfilename, …                   ‘gui_Singleton’,  gui_Singleton, …                   ‘gui_OpeningFcn’, @TUGASMATEMATIKA_OpeningFcn, …                   ‘gui_OutputFcn’,  @TUGASMATEMATIKA_OutputFcn, …                   ‘gui_LayoutFcn’,  [] , …                   ‘gui_Callback’,   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});end if nargout    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else    gui_mainfcn(gui_State, varargin{:});end% End initialization code – DO NOT EDIT

        % — Executes just before TUGASMATEMATIKA is made visible.function TUGASMATEMATIKA_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject    handle to figure% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% varargin   command line arguments to TUGASMATEMATIKA (see VARARGIN) % Choose default command line output for TUGASMATEMATIKAhandles.output = hObject; % Update handles structureguidata(hObject, handles); % UIWAIT makes TUGASMATEMATIKA wait for user response (see UIRESUME)% uiwait(handles.figure1);

        % — Outputs from this function are returned to the command line.function varargout = TUGASMATEMATIKA_OutputFcn(hObject, eventdata, handles) % varargout  cell array for returning output args (see VARARGOUT);% hObject    handle to figure% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Get default command line output from handles structurevarargout{1} = handles.output;

        % — Executes on button press in pushbutton1.function pushbutton1_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton1 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

        % — Executes on button press in pushbutton2.function pushbutton2_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton2 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

        % — Executes on button press in pushbutton3.function pushbutton3_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton3 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

        % — Executes on button press in pushbutton4.function pushbutton4_Callback(hObject, eventdata, handles)% hObject    handle to pushbutton4 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)close

        function edit1_Callback(hObject, eventdata, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit1 as text%        str2double(get(hObject,’String’)) returns contents of edit1 as a double

        % — Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit1 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

        function edit2_Callback(hObject, eventdata, handles)% hObject    handle to edit2 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit2 as text%        str2double(get(hObject,’String’)) returns contents of edit2 as a double

        % — Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit2 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

        function edit3_Callback(hObject, eventdata, handles)% hObject    handle to edit3 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit3 as text%        str2double(get(hObject,’String’)) returns contents of edit3 as a double

        % — Executes during object creation, after setting all properties.function edit3_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit3 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

        function edit4_Callback(hObject, eventdata, handles)% hObject    handle to edit4 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit4 as text%        str2double(get(hObject,’String’)) returns contents of edit4 as a double

        % — Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit4 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

        function edit5_Callback(hObject, eventdata, handles)% hObject    handle to edit5 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit5 as text%        str2double(get(hObject,’String’)) returns contents of edit5 as a double

        % — Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit5 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

        function edit6_Callback(hObject, eventdata, handles)% hObject    handle to edit6 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA) % Hints: get(hObject,’String’) returns contents of edit6 as text%        str2double(get(hObject,’String’)) returns contents of edit6 as a double

        % — Executes during object creation, after setting all properties.function edit6_CreateFcn(hObject, eventdata, handles)% hObject    handle to edit6 (see GCBO)% eventdata  reserved – to be defined in a future version of MATLAB% handles    empty – handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows.%       See ISPC and COMPUTER.if ispc && isequal(get(hObject,’BackgroundColor’), get(0,’defaultUicontrolBackgroundColor’))    set(hObject,’BackgroundColor’,’white’);end

  5. Pak mau bertanya..
    Untuk pesan load kan hanya satu tempat edit ya, kalo seandainya saya ingin membuka file txt yang isinya misalkan angka 1 2 3. Dan angka tersebut muncul di tag edit1,edit2,edit 3. jadi satu file bisa dibuka di 3 edit dengan isinya 1 angka saja.
    Bagaimana cara loadnya pak ?

  6. Assalamualaikum pak,,mf mengganggu pak, pak sy mau bertanya, bagaimana caranya memanggil data pada file *.mat dan menampilkan data tersebut pada tabel GUI matlab,, sy sudh mencoba beberpa kali pak tpi sy tidak berhasil menampilkan data tersebut pada tabel matlab, terimksi sebelumnya pak, mohon bantuannya

    1. seperti biasa, pake load, trus errornya emang gimana? buku database dgn matlab sedang dicek ulang (di pict kanan bawah site ini)

  7. ndk ada errornya pak,,dia membaca bahwa file itu ada hnya sja dia ndk bisa tampil di table guinya pak,,
    pak bisa memang kita panggil data .mat dan menampilkannya di table dengan script?

  8. assalamualaikum pak,, saya mau nanyak gimana cara nya agar begitu kita klik tombol push button langsung keluar beberapa contoh gambar wajah yang kita sediakan,,,
    dan gimna cara menyimpan gambar wajah yang sudah kita capture secara realtime tiap kali kita mengcapture nya,,tanpa menghapus hasil capture yang sebelumnya

  9. Assalamualaikum
    permisi pak rahma saya mau tanya.
    kalo misalkan saya punya button 1 buat buka gambar di axis1, button 2 buat rgb2gray di axis2 sama nama gambar di edit text1. abis itu saya buka gambar terus kan muncul nama nya di edit text1 terus saya mau buka gambar lagi tapi nama gambar di edit text1 masih nama gambar yang pertama saya buka, supaya ke reset itu gimana ya pak?
    terimakasih

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s