Uvod u MATLAB 2013 / 2014 god. Vii asistent : Dr. Edin Mujid Ibrahim ehid br.indexa:704 Pregledano : Domaa zadaa br.8: Proizvoljni zadatak sa gui(Graphical User Interfaces ) . Kalkulator koji proraunava potreban otpornik za spajanje LED dioda, u seriju, paralelno ili samo jedna dioda.
Zadatak: Proizvoljni zadatak sa gui(Graphical User Interfaces ) . Kalkulator koji proraunava potreban otpornik za spajanje LED dioda, u seriju, paralelno ili samo jedna dioda. Rjeenje : function varargout = untitled1(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @untitled1_OpeningFcn, ... 'gui_OutputFcn', @untitled1_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 function untitled1_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); axes(handles.axes1) imshow('led_1.gif') axes(handles.axes2) imshow('led_2.gif') axes(handles.axes3) imshow('led_3.gif') function varargout = untitled1_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;
function popupmenu1_Callback(hObject, eventdata, handles) v=get(handles.popupmenu1,'value') if v == 2 set(handles.brojdioda, 'Visible', 'off') end if v == 3 set(handles.brojdioda, 'Visible', 'on') end if v == 4 set(handles.brojdioda, 'Visible', 'on') end function popupmenu1_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function brojdioda_Callback(hObject, eventdata, handles) function brojdioda_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function napondiode_Callback(hObject, eventdata, handles) function napondiode_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function strujadiode_Callback(hObject, eventdata, handles) function strujadiode_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function otpornik_Callback(hObject, eventdata, handles) function otpornik_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function snagaotpornika_Callback(hObject, eventdata, handles) function snagaotpornika_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function pushbutton1_Callback(hObject, eventdata, handles) izvor = str2double(get(handles.naponizvora,'string')) brojdioda = str2double(get(handles.brojdioda,'string')) napondiode = str2double(get(handles.napondiode,'string')) strujadiode = str2double(get(handles.strujadiode,'string'))
menu = get(handles.popupmenu1,'Value') if menu == 2 R = (izvor - napondiode)*1000/strujadiode P=((izvor-napondiode)*strujadiode)/1000 set(handles.otpornik,'string',num2str(R)) set(handles.snagaotpornika,'string',num2str(P)) end
if menu == 3 R = (napondiode*brojdioda)*1000/strujadiode P=((izvor-napondiode*brojdioda)*strujadiode)/1000 set(handles.otpornik,'string',num2str(R)) set(handles.snagaotpornika,'string',num2str(P))
end
if menu == 4 R = ((izvor - napondiode)*1000)/(strujadiode*brojdioda) P=((izvor-napondiode)*strujadiode*brojdioda)/1000 set(handles.otpornik,'string',num2str(R)) set(handles.snagaotpornika,'string',num2str(P)) end function pushbutton2_Callback(hObject, eventdata, handles) set(handles.naponizvora,'string','') set(handles.brojdioda,'string','') set(handles.napondiode,'string','') set(handles.strujadiode,'string','')
set(handles.otpornik,'string','') set(handles.snagaotpornika,'string','') function pushbutton3_Callback(hObject, eventdata, handles) close all
function naponizvora_Callback(hObject, eventdata, handles) function naponizvora_CreateFcn(hObject, eventdata, handles) if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
Zakljuak: Matlab je programski paket namijenjen znanstvenim i tehnikim proraunima, koji objedinjuje alate za raunanje, vizualizaciju i programiranje. Osnovna funkcija korisnikog suelja (engl. user interface) jest olakavanje komunikacije ovjeka i raunala. Kreiranje grafikog suelja u Matlabu odvija se u tri koraka:
1. dizajniranje grafikog sulja dodavanjem i razmjetanjem kontrola 2. programiranje kontrola da rade neto 3. pokretanje grafikog suelja Koristedi paletu za odabir kontrola dodajemo kontrole na sliku koja predstavlja grafiko suelje. Kontrole za ulaz/izlaz Push Buttons Check Boxes Radio Buttons Edit Text Static Text Sliders Frames Popup Menus Axis Svaka kontrola ima svoju grupu svojstava koja se postavljaju u prozoru Property Editor