Thursday, October 31, 2013

Menggunakan input field GUI di MATLAB

Berikut adalah contoh penggunaan input field di MATLAB.



adapun sourcenya adalah:
function tes_button
clc; 
figure('menubar', 'none', 'position', [300 300 200 100]); 

 uicontrol('style', 'pushbutton','position', [10 10, 100 50], 'string', 'TEST'...
 ,  'Callback', @call ); 

edit = uicontrol('style', 'edit','position', [10 65, 60 30], 'string', '0'.... 
    ,'fontsize', 12, 'fontweight','bold');

tampil = uicontrol('style', 'text', 'position', [80 65 60 25], 'string' , '0' ...
      ,'fontsize', 12, 'fontweight','bold'); 

        function call(varargin)
            a = get(edit, 'string'); 
            if ~isnan(str2double(a))
                set(tampil, 'string', a); 
            else
                set(tampil, 'string', 'SALAH');
            end
        end
end

No comments: