microsoft word - matlab grafiksel kullan

86
HARUN YALÇIN Sayfa 1 31.10.2006 HAZIRLAYAN: HARUN YALÇIN Bu belge hazırlanırken kullanılan matlab 6 versiyonudur ve üst versiyonlarda benzer sekillerde calıstırılmakla birlikte aynı sekilde işlemler yürütülür. Program geliştirme aşamasında yazılan kodlar matlab kodları olduklarından matlab programlamayı öğrendikten sonra matlab grafiksel arayüzle programlamayı öğrenmenizi tavsiye ederim Bazı durumlarda karsılastıgım sorunları konuları anlatırken belirttim. Đlgilenen herkese yardımcı olması dileklerimle.

Upload: ozan-kosun

Post on 01-Dec-2014

988 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 1 31.10.2006

HAZIRLAYAN: HARUN YALÇIN Bu belge hazırlanırken kullanılan matlab 6 versiyonudur ve üst versiyonlarda benzer sekillerde calıstırılmakla birlikte aynı sekilde işlemler yürütülür. Program geliştirme aşamasında yazılan kodlar matlab kodları olduklarından matlab programlamayı öğrendikten sonra matlab grafiksel arayüzle programlamayı öğrenmenizi tavsiye ederim Bazı durumlarda karsılastıgım sorunları konuları anlatırken belirttim. Đlgilenen herkese yardımcı olması dileklerimle.

Page 2: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 2 31.10.2006

MATLAB KULLANICI ARAYÜZÜ GĐRĐŞ: Günümüzde kullandıgımız programların hemen hemen tamamı grafiksel tabanlı programlar oldugundan dolayı matlab programıda yeni sürümlerinde ( 6 ve üstü) grafiksel arayüz ile programlamayı (GUI) kullanıcıya sunmustur. GUI programların son kullanıcıya fare veya klavye ile ulasabilecekleri veriler sunmaktadır. Ayrıca matlab arayüz programları m-function ile olusturulabilse de bu kodları yazmak hem programcı tarafından zor hemde zaman kaybı olusturacagından GUI ile programlama göz önünde tutulmalıdır. Önemli Not:Matlab arayüz programlarında matlabta kullanılan tüm komutlar kullanılabilir ve icra edilebilir. MATLAB GUI CALISMASI Matlab GUI nin calısması belirli 3 temel özellik içerir. 1-GUI yüzeyi 2-GUI objeleri 3-Đşlevler GUI YÜZEYĐ GUI yüzeyi programda kullandıgınız bütün objelerin bulundugu kısımdır.Guı yüzeyi elemanların yerlestirildiği ve görsel temanın saglandıgı kısımda denilebilir. GUI OBJELERĐ GUI objeleri programı olustururken kullandıgımız buton,slider,axes gibi herbirinin kendine ait bir işlevi olan ve bu işlevlere göre programcının olusturdugu program yapısında calısan elemanlardır. ĐŞLEVLER En önemli kısım olan işlevler kısmı(CALLBACK) bir nesnenin ne yapması gerektiği belirtilen kısımdır.Gercekte eger m-function seklinde yazılan grafik tabanlı programlarda nesnelerin callback(işlevleri) nin belirtilmesi gerekir fakat GUI penceresinde yapacagımız programlar için matlab GUI nesnelerin işlevlerini otomatik olarak atamaktadır.Bu yüzden işlevler GUI de daha kolay bir hal almaktadır. GUI penceresinin acılması 2 sekilde gerceklesebilir. 1-Komut satırında guide yazılarak 2-file�new�guı

Page 3: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 3 31.10.2006

yolu izlenerek.Bu işlemlerden herhangi birini yaptıgınızda asagıdaki görüntüyü elde edeceksiniz.Đkonlar ve pencere yüzeyindeki acıklamalar görülmektedir

GUI FĐGUR YÜZEYĐ BOYUTLANDIRMA KULAKCIGI VE PĐKSEL CETVELĐ Figür yüzeyi programcının programı olustururken nesneleri yerlestirecegi alan olarak görülmektedir.Figür yüzeyinin boyutunu olusturulan programın ekranda kaplayacagı yeri düsünülerek veya figür üzerinde nesnelerin karmasından kacınılacak büyüklükte secilmesi önemlidir.Figür yüzeyinin boyutlanması farenin yüzey boyutlandırma kulakcıgının üzerine getirilmesi sonucu farenin sol tusuna basılı tutularak istenilen sekilde sürüklenmesi durumunda figür yüzeyinin boyutu ayarlanabilir. Figur yüzeyinin boyutu ayarlandıktan sonra gereken ise figür yüzeyine yerlestirilen nesnelerin guı yüzeyinde istenilen konuma getirilmesi için gereken piksel seviyesinin secimidir.GUI penceresinde Layout�Grid and Rules yolu izlenerek piksel cetveli için gereken ayarlmalar yapmak mümkündür.Asagıda piksel cetveli ayarları görülüyor.

Page 4: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 4 31.10.2006

Bu pencerede Grid Size yazan kısmda değişiklik yaparsanız figür yüzeyindeki birim sürükleme burada yazılan piksel degerine karsılık gelir.Bu degerin düsük tutulması nesneler arasında boslukların cok büyük olmamasını saglayacaktır.Bu yüzden bu degere yaklasık 20 degerini vermek uygun olacaktır.Ayrıca snap to grid kutucugunun işaretlenmesi yararlı olacaktır. GUI OBJE KUTUSU

Nesne kutusunda bulunan nesneler ve isimleri yukarıdaki gibidir. Bu nesnelerden herhangi biri sürüklenip bırakılmak suretiyle figur penceresinde olusturulur . MATLAB GUI HĐZALAMA DÜGMESĐ Obje hizalama dügmesi tıklandıgında asagıdaki pencere acılacaktır.

Page 5: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 5 31.10.2006

Bu pencere yardımıyla guı figür yüzeyi üzerinde bulunan nesnelerin yatay(horizantal) ve düsey( vertical) seklinde hizalama(align) ve dagıtma(distribute) islemleri gerceklestirilebilmektedir. MATLAB GUI MENÜ EDĐTÖRÜ

Page 6: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 6 31.10.2006

Menu editörü grafiksel programa , programcının istediği içeriklere sahip bir menü veya sag tus menüsü tasarlamaya yarar.Programlar olusturulduktan sonra istenirse ekranın yazıcıdan cıktı alınması kaydetme dosya acma gibi işlemler menüye eklenerek calıstırılabilir. MATLAB GUI OBJE LĐSTESĐ Bu tus ile guı yüzeyinde bulunan objelerin listesi alınabilir. MATLAB GUI STANDART ARAC CUBUGU Guı arac cubugu standart içerikler yanında değişik içeriklerde saglamaktadır. FĐLE New---------yeni pencere ac Open--------dosya ac Close-----aktif fiğürü kapat Save------aktif fiğürü kaydet Save as----aktif figürü farklı kaydet Preferences---tercihler(ayarlar) Print--------yazdır Burada preferences penceresi acıldıgında asagıdaki görüntü alınır.

Buradan istenilen özellikler ayarlanabilir.

Page 7: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 7 31.10.2006

Show names in component palette sekmesi işaretli ise nesnelerin alt alta sıralandıgı obje kutusu secilmiş olur. EDĐT Edit menüsü standart içerikler dısında Inspect properties secenegi ile obje özellikleri penceresine ulasılır. LAYOUT Align objects-----------obje hizalama Grid and rules----------piksel cetveli ve bölmelendirme Snap to grid------------bölümlenmiş alana oturtma Menü editor-----------menü editörü Bring to front---------objeyi en öne getirme Send to back----------objeyi en arkaya gönderme Bring forwad--------objeyi bir adım öne getirme Send backward-------objeyi bir adım geri gönderme TOOLS Property inspector----obje özellikleri penceresi Object browser-------obje listesi Application options—uygulama özellikleri Activate figure-------uygulama baslatma düğmesi Tools menusunden application options(uygulama özellikleri) secildiğinde Asagıdaki pencere acılacaktır.

Page 8: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 8 31.10.2006

Bu pencerede adı gecen Resize behavior (boyutlandırma) Non-resizable-------uygulama penceresinin boyutu kullanıcı tarafından değiştirilemez Proportional-------uygulama penceresinin boyutu kullanıcı tarafından orantılı değiştirilir User-specified---uygulama penceresinin boyutu istenilen sekilde değiştirilir. Command-line accessibility (komut satırı erişimi) Off------------------------komut satırından guı figurine etkileşim engellenir On-------------------------komut satırından guı figurune etkileşim saglanır User-specified-----------obje özellikleri penceresinden etkileşime izin verir Bu pencerede diger secenekler ise kod yıgınları ile ilgili konulardır ve varsayılan sekilde kalmasında yarar vardır. MATLAB GUI PROGRAMLAMA Programlama yapılmadan önce kodlamada kullanacagımız en öncelikli komutları ve işlevlerini sıralayacak olursak Komut,değişken,özellik Acıklaması Gcbf Calısılmakta olan guı figüründe Gcbo Calısılmakta olan guı objesinde Persistent Sabit deger komutu Global Ortak değişken komutu Save Dosya kaydetme komutu Load Dosya yükleme komutu Đsempty Đlk deger komutu Char Karaktere dönüstürme Str2num sayıya dönüstürme Set Atama komutu Get Alma komutu Sprintf Karakter dizisi yaratma Fprintf Ekran cıktısı alma komutu Findobj Objeyi buldurma komutu Tag Obje etiketi Value Obje degeri string Obje adı Pushbutton Uygulaması Push buton aslında bir kontrol butonu olup istenilen bir işlevin gerceklesmesi için bu butona fare ile tıklanması gereken yerlerde kullanılır. Buradaki örnegimizde butona tıklandıgında figür penceresinde bütün programcılara inat merhaba dünya yerine HOŞÇAKAL DÜNYA yazdıracagız Matlab�new�guı yolu izleyerek bir guı penceresi acın.Figur yüzeyini kulakcıktan sürükleyerek istenilen bir boyuta getirin Layout menusunden Grid and rules e tıklayarak piksel ve bölmelendirme penceresini acın ve Grid size bölümünü 20 ye ayarlayın ve snap to grid secenegini işaretleyin ve ok dügmesine tıklayın. Nesne kutusundan 1 pushbuttonu sürükleyerek figur penceresine bırakın.Yine aynı sekilde nesne kutusundan 1 static text i sürükleyerek figur penceresine bırakın.Nesnelerden

Page 9: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 9 31.10.2006

herhangi biri üstüne tıkladıgınızda nesnenin boyutunu belirleyebileceginiz siyah noktalar belirecektir.bu noktalardan sürüklerseniz nesne boyutunu ayarlayabilirsiniz.En son ekran görüntüsü asagıdaki gibi olacaktır.

Bu durumda iken push button üzerine çift tıklarsanız veya buton üzerine gelip sag tıklayıp acılan menuden inspect properties sekmesini secerseniz karsınıza bu pushbutton özelliklerini gösterir pencere acılacaktır. Bu özellikler penceresinden bahsedelim biraz.Bütün nesnelerin ve ayrıca figur penceresinin kendine ait bir özellikler penceresi mevcuttur.Programcı yani siz hangi nesnenin hangi özelliğine ulasmak istiyorsanız bu özellikler penceresinden gerekli yerleri düzenleyerek gerekli işlemleri veya gerekli görsel temaları saglayabilirsiniz. Buton özelliklerinde bizim işimize yarayacak kısımları acıklarsak.En bastaki özellik background sekmesidir.Bunun yanında bulunan kücük kutucuga tıklarsanız istedğiniz buton rengini burdaki degerlerle oynayarak gösterebilirsiniz. Callback kısmı otomatik olarak atanacagından burası ile işlem yapmamanız önemlidir. Font yazan bütün sekmeler buton üzerinde ki yazının biçimi büyüklügü kalınlıgı gibi özellikleri belirler. Foregroundcolor kısmı buton üzerindeki yazının rengini belirler. String kısmı buton üzerine yazılan yazıdır.Genellikle bu özellik programcı tarafından ayarlanır Tag buton etiketidir degiştirmemeniz önerilir. Uıcontextmenu sag tus menusu En alttaki visible kısmı butonun acılısta görünür olup olmama durumudur.On ----görünürlük off----görünmezlik

Page 10: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 10 31.10.2006

Ayarları yapalım Buton özellikler penceresinde Background kısmındaki kücük ikona tıklayarak bütün kısımları 33 olarak ayarlayın. Fore groundcolor kısmındakileri 100 ,100,0 olarak ayarlayın. String kısmını silip oraya ‘YAZ’ yazın(tırnaklar yok) ve enterlayıp pencereyi kapatın NOT:Matlabta kullandıgınız değişkenler,stringler,yazıların hiç biri Türkçe karakter içermemelidir. Đşlemimiz bu kadar. Son ekran görüntüsü asagıdaki gibi olacak.

Page 11: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 11 31.10.2006

Bu asamadan sonra kodlama işlemine geciyoruz. File�Save As derseniz karsınıza bir kaydetme penceresi acılacak ve buraya uzantısı .fig olmak üzere ‘buton.fig’ yazıp kaydedin.Kaydetme işlemi biter bitmez karsınıza buton.m adlı bir m-fuction dosyası cıkacaktır.Bu m-function dosyasının içeriği su sekildedir. function varargout = buton(varargin) % BUTON Application M-file for buton.fig % FIG = BUTON launch buton GUI. % BUTON('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 17-Oct-2006 03:16:04 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK

Page 12: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 12 31.10.2006

try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. disp('pushbutton1 Callback not implemented yet.')

Page 13: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 13 31.10.2006

Bu m-function dosyasında programlamanın yapılacagı kısımlar function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) gibi nesne taglarının gectiği kısımlardır.Programlamada en önemli özellik nesnelerin etiketleridir(taglar).Nesnelere işlev kazandırmak için bu etiketler kullanılır. Bu m-function dosyasın daki disp('pushbutton1 Callback not implemented yet.') yazan yerleri silebilirsiniz. Yapacagımız işlemlere göre kod yazmaya baslayalım.Yazacagımız kodlar asagıdaki gibidir.%ile baslayan satırlar acıklama satırları oldugundan sadece siz ögrenenlerin kodu bilmesi için yazıyorum bunları m-function dosyasına yazmanıza gerek yok. Sildiğiniz disp('pushbutton1 Callback not implemented yet.') satırından baslamak üzere asagıdaki gibi kodları yazınyazın % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. a=findobj(gcbf,'tag','text1');%calisan figurde etiketi text1 olan nesneyi bul ve a ya ata set(a,'string','HOSCAKAL DUNYA')%a nin string degerini HOSCAKAL DUNYA olarak ata (Tırnak işaretlerine dikkat edin) daha sonra kaydetme butonuna basarak kaydedin. Guı figurundeki active figure butonuna basarsanız asagıdaki görüntüleri alacaksınız.

butona basmadan önce butona bastıktan sonra Buradan sonra figür yüzeyinin özelliklerini inceleyelim. Yaptıgımız Buton.fig dosyası üzerinde bos bir yerde cift tıklayıp figure özelliklerini acın. Bu özellikler içinde Color sekmesi figure yüzeyinin rengini ayarlamaya yarar. Filename baglı bulundugu dosyanın yolunu gösterir. Handlevisibility cizimleri figur penceresinde gösterir(axes uygulamaları için lazım) Menübar figure olarak ayarlarsanız standart figur menusunu programa ekler Name kısmı ise program calıstıgında görülecek olan program yazısını yazabileceginiz yerdir. Paper yazan tüm sekmelerde figürenin kagıt düzlemi ile ilgili bilgilerini girebilir veya değiştirebilirsiniz Windowstyle ise pencere stilini ayarlayabilirsiniz Ayarlamaları yapalım.

Page 14: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 14 31.10.2006

Color rengi 0,100,100 olarak ayarlayın Menübar ı figure olarak ayarlayın Name kısmına ‘yazı yaz’ seklinde yazın(tırnaklar yok) Ve programı calıstırın ekranda son yaptıgnız değişiklikleri kaydedip kaydetmeyeceginizi soran bir diyalog kutusu acılacak buna yes dedikten sonra program calısacaktır programda ne gibi değişiklikler oldugunu göreceksiniz. Toggle Button Uygulaması Bu uygulamayla birlikte sadece .fig dosyası ve .m kod dosyası incelenecektir. Toogle button 2 farklı durumu incelemek için kullanılır.Toogle button basılı konumda iken degeri 1 ,basılı değilken degeri 0 dır. Buna göre basit bir uygulama gerceklestirelim Örnegimizde toogle butonun basılı olmadıgı konumda figurde ‘BASILI DEĞĐL’,togglebuton nun basılı oldugu konumda ise ‘BASILI’ yazdıracagız. Figur yüzeyimize bir statik text ve bir tanede toogle button yerlestirin. Gerekli boyutlandırma işlemini yapın. Statik text e cift tıklayıp özellikler menüsünü acın Backgroundcolor 0,100,0 olarak ayarlayın String kısmını silin ve bos bırakın Bu ayarlamalardan sonra entere basın ve daha sonra bu pencereyi kapatıp cıkın Toogle button üzerine çift tıklayarak özellikler menüsünü acın. Özellikler menüsünden sadece string kısmını silip buraya ‘DURUM’ yazın. Daha sonra enterlayıp ,pencereyi kapatın Figure yüzeyi özelliklerini acıp name kısmına ‘TOOGLE’ yazın ve enterlayıp pencereyi kapatın. Bu durum sonrası son durum asagıdaki gibi olacaktır

Page 15: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 15 31.10.2006

Figur penceremizi tooglebutton.fig olarak kaydedin.Karsınıza cıkacak m-function dosyası asagıdaki gibi olacaktır. function varargout = tooglebutton(varargin) % TOOGLEBUTTON Application M-file for tooglebutton.fig % FIG = TOOGLEBUTTON launch tooglebutton GUI. % TOOGLEBUTTON('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 17-Oct-2006 17:00:03 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard

Page 16: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 16 31.10.2006

catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = togglebutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.togglebutton1. disp('togglebutton1 Callback not implemented yet.')

Page 17: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 17 31.10.2006

Bu m-dosyadaki en altta bulunan disp('togglebutton1 Callback not implemented yet.') kısmını silin bütün uygulamalarda bütün nesneler için silinmesi gerekir. Silinen satırdan baslamak suretiyle sagıdaki komutları yazın % -------------------------------------------------------------------- function varargout = togglebutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.togglebutton1. global durum %ortak değisken durum tanımlanır durum=get(gcbo,'value'); %toogle buttonun value degerini durum değişkenine ata a=findobj(gcbf,'Tag','text1'); %etiketi text1 olan nesneyi figurde bul ve a’ ya ata if durum==0 %eger value deger 0 ise set(a,'string','BASILI DEGIL'); %text1 in string ini Basılı değil olarak değiştir else %value deger 1 ise set(a,'string','BASILI KONUMDA'); % text1 in stringini Basılı konumda olarak değiştir. end Programı calıstırdıgınız da asagıdaki gibi calıstıgını göreceksiniz.Fakat burada bilmeniz gereken ince bir ayrıntı var.Program calıstıgında baslangıcta hiç bir sey yazmayacaktır.Bunun nedeni baslangıca bir sey atamamıs olmamızdan kaynaklanıyor.Bunun için baslangıcta toogle button un basılı olmadıgı konumu alırsak static text in string kısmına ‘BASILI DEGIL’ seklinde yazmak uygun olacaktır.

Page 18: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 18 31.10.2006

RADĐO BUTTON UYGULAMASI Radio buttonların genel kullanım biçimi kullanıcının bir kac secenekten sadece birini secmesini saglamaktır.radiobutton secili durumdayken degeri 1 secilmemiş durumdayken degeri 0 dır.Pratikte radiobutonlarıda checkbox gibi aynı anda birden cok secim yapma imkanıda saglanabilir.Fakat yaygın kullanımı tek secim oldugundan burada da böyle bir uygulama yapacagız. Örnegimizde bir cok yerde karsımıza cıkan bir soruya yanıt vermeden yola cıkarak soruya radiobutton ile yanıt vermeyi görecegiz. Figur yüzeyimize 2 tane static text ve 3 tanede radiobutton yerlestirin.Bütün nesnelerdeki stringleri asagıdaki sekilde görüldügü gibi değiştirin, Etiketi radiobutton1 olan radio butonu bulup özellikler penceresini acın.Özellikler penceresinden value sekmesine tıklayın..Acılacak kücük kutucukta 0 degerini 1 olarak değiştirip OK dügemsine tıklarsanız.Radiobuttonun baslangıcta secilmiş olmasını saglarsınız veya hiçbir değişiklik yapmadan baslangıcta hepsinin secilmemiş konumda kalmasını da saglayabilirsiniz Son durumda ki ekran görüntüsü.

Bu figuru radiobutton.fig olarak kaydedin ve karsınıza cıkacak m-function dosyasını asagıdaki gibi kodlayın function varargout = radiobutton(varargin) % RADIOBUTTON Application M-file for radiobutton.fig % FIG = RADIOBUTTON launch radiobutton GUI. % RADIOBUTTON('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 17-Oct-2006 17:55:52 if nargin == 0 % LAUNCH GUI

Page 19: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 19 31.10.2006

fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more

Page 20: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 20 31.10.2006

%| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = radiobutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.radiobutton1. durum=get(gcbo,'value'); b=findobj(gcbf,'Tag','radiobutton2'); c=findobj(gcbf,'Tag','radiobutton3'); d=findobj(gcbf,'Tag','text2'); if durum==1 set(b,'value',0); set(c,'value',0); set(d,'string','TURKIYE CUMHURIYETI'); end % -------------------------------------------------------------------- function varargout = radiobutton2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.radiobutton2. durum=get(gcbo,'value'); a=findobj(gcbf,'Tag','radiobutton1'); c=findobj(gcbf,'Tag','radiobutton3'); d=findobj(gcbf,'Tag','text2'); if durum==1 set(a,'value',0); set(c,'value',0); set(d,'string','KKTC'); end % -------------------------------------------------------------------- function varargout = radiobutton3_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.radiobutton3. durum=get(gcbo,'value'); a=findobj(gcbf,'Tag','radiobutton1'); b=findobj(gcbf,'Tag','radiobutton2'); d=findobj(gcbf,'Tag','text2'); if durum==1 set(a,'value',0); set(b,'value',0); set(d,'string','DIGER'); end

Page 21: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 21 31.10.2006

Kodlar incelenecek olursa tek radiobutton üzerinden incelemeye baslayalım durum=get(gcbo,'value'); satırı içinde bulunulan radiobutton un o andaki value degerini durum değişkenine ata b=findobj(gcbf,'Tag','radiobutton2'); c=findobj(gcbf,'Tag','radiobutton3'); satırları aktif figurde etiketleti sırasıyla radiobutton2 ve radiobutton3 olan nesneleri bul ve sırasıyla b ve c değişkenlerine ata.(2 ve 3. radiobuttonlarda ise a değişkenine radiobutton1 atanmıstır) d=findobj(gcbf,'Tag','text2'); satırı aktif figurde etiketi text2 olan nesneyi bul ve d değişkenine ata demektir if durum==1 set(b,'value',0); set(c,'value',0); set(d,'string','TURKIYE CUMHURIYETI'); end Yukarıdaki if yapısı durum değişkeninin degeri 1 ise diger radiobuttonların degerlerini 0 yap manasındadır.Bu durumda her seferde tek bir radiobutton secilmiş olur.Eger diger radio butonlara 0 degerini atamaz iseniz aynı anda birden fazla radiobutton secebilirsiniz. En son set(d,'string','TURKIYE CUMHURIYETI'); satırı ise text2 nin string degerini TURKIYE CUMHURIYETI olarak atanmasını saglar.Diger radiobuttonlardada mantık aynıdır.Sadece yazılan yazı ve değişkenler farklılık gösterir. Đkinci bir durum olarak bilinmesi gereken program calıstıgında radiobutton1 aktif oldugundan program calısır calısmaz ekranda TURKIYE CUMHURIYETI yazması gereklılıgıdır.Bunuda static text2 nin string kısmını TURKIYE CUMHURIYETI olarak degıstırmenız ile yapabileceksiniz.En son durumdaki ekran görüntüsü asagıdaki gibi olacaktır.

CHECKBOX UYGULAMASI Checkboxlar aynı anda birden fazla secimin yapılabildiği uygulamaalrda kullanılmaktadır. Checkbox un secili olma durumu 1 secili olmama durumunda degeri 0 olarak belirlenir. Örnegimizde kodların cok fazla uzamaması için sadece 3 checkbox ile sonuc üretilmiştir.

Page 22: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 22 31.10.2006

Figür yüzeyine 2 static text ve 3 tanede checkbox u yerlestirip asagıdaki sekilde görülen ayarlamaları yapın.

Bu ayarlamaları yaptıktan sonra bunu checkbox.fig olarak kaydedin.Karsımıza cıkan m-function dosyasını asagıdaki gibi kodlayın function varargout = checkbox(varargin) % CHECKBOX Application M-file for checkbox.fig % FIG = CHECKBOX launch checkbox GUI. % CHECKBOX('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 18-Oct-2006 02:32:11 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end

Page 23: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 23 31.10.2006

elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = checkbox1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.checkbox1. global durum1

Page 24: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 24 31.10.2006

global durum2 global durum3 sd1=findobj(gcbf,'Tag','checkbox1'); durum1=get(sd1,'value'); sd2=findobj(gcbf,'Tag','checkbox2'); durum2=get(sd2,'value') sd3=findobj(gcbf,'Tag','checkbox3'); durum3=get(sd3,'value') str=findobj(gcbf,'Tag','text2'); if durum1==1 & durum2==0 & durum3==0 set(str,'string','kopek'); elseif durum1==1 & durum2==1 & durum3==0 set(str,'string','kopek ve kedi'); elseif durum1==1 & durum2==1 & durum3==1 set(str,'string','kopek,kedi ve kus'); elseif durum1==0 & durum2==1 & durum3==0 set(str,'string','kedi'); elseif durum1==0 & durum2==1 & durum3==1 set(str,'string','kedi,kus'); elseif durum1==0 & durum2==0 & durum3==1 set(str,'string','kus'); elseif durum1==1 & durum2==0 & durum3==1 set(str,'string','kopek ve kus'); end end end end end end end % -------------------------------------------------------------------- function varargout = checkbox2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.checkbox2. global durum1 global durum2 global durum3 sd1=findobj(gcbf,'Tag','checkbox1'); durum1=get(sd1,'value'); sd2=findobj(gcbf,'Tag','checkbox2'); durum2=get(sd2,'value') sd3=findobj(gcbf,'Tag','checkbox3'); durum3=get(sd3,'value') str=findobj(gcbf,'Tag','text2'); if durum1==1 & durum2==0 & durum3==0 set(str,'string','kopek'); elseif durum1==1 & durum2==1 & durum3==0 set(str,'string','kopek ve kedi'); elseif durum1==1 & durum2==1 & durum3==1 set(str,'string','kopek,kedi ve kus'); elseif durum1==0 & durum2==1 & durum3==0

Page 25: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 25 31.10.2006

set(str,'string','kedi'); elseif durum1==0 & durum2==1 & durum3==1 set(str,'string','kedi,kus'); elseif durum1==0 & durum2==0 & durum3==1 set(str,'string','kus'); elseif durum1==1 & durum2==0 & durum3==1 set(str,'string','kopekve kus'); end end end end end end end % -------------------------------------------------------------------- function varargout = checkbox3_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.checkbox3. global durum1 global durum2 global durum3 sd1=findobj(gcbf,'Tag','checkbox1'); durum1=get(sd1,'value'); sd2=findobj(gcbf,'Tag','checkbox2'); durum2=get(sd2,'value') sd3=findobj(gcbf,'Tag','checkbox3'); durum3=get(sd3,'value') str=findobj(gcbf,'Tag','text2'); if durum1==1 & durum2==0 & durum3==0 set(str,'string','kopek'); elseif durum1==1 & durum2==1 & durum3==0 set(str,'string','kopek ve kedi'); elseif durum1==1 & durum2==1 & durum3==1 set(str,'string','kopek,kedi ve kus'); elseif durum1==0 & durum2==1 & durum3==0 set(str,'string','kedi'); elseif durum1==0 & durum2==1 & durum3==1 set(str,'string','kedi,kus'); elseif durum1==0 & durum2==0 & durum3==1 set(str,'string','kus'); elseif durum1==1 & durum2==0 & durum3==1 set(str,'string','kopek ve kus'); end end end end end end end

Page 26: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 26 31.10.2006

Burada tek bir checbox için yazılan kodların hepsi diğer checboxlar içinde aynıdır.Kodlar acıklanırsa durum1 durum2 ve durum3 global değişkenler olmak üzere durum1 e checkbox1 in o anki degeri durum2 ye checkbox2 nin o anki degeri ve durum3 e ise checkbox un o anki degeri atanmıstır.Yani checkbox ların secili olup olmamasına göre durum degişkenleri 1 veya 0 degerini alıyorlar. Buna göre bir secme algoritması olusturuyoruz if else if yapısı ile durum degişkenlerinin alacagı bütün durumlar ve bunlara karsılık gelen secimler ekrana yazdırılıyor. Her if içinde bir end blogu ekliyoruz. Programın son hali asagıdaki gibidir.

EDĐT TEXT UYGULAMASI Edit text son kullanıcının bilgi girişi yapacagı giriş kutusu olarak düsünülebilir.Fakat programcının bilmesi gereken en önemli nokta edit texte girilen bütün girişlerin karakter tipi olarak algılanacagıdır.Örnegin giriş olarak 1000 sayısı olarak girip bunu bu sekilde matematiksel işlemlere sokamazsınız.Bunun için kodlamada girilen karakter bilgisini numerik forma cevirmeniz gerekir.Aynı sekilde numerik bir cıkısı göstermek istiyorsanız bu numerik cıkısı karaktere cevirmelisiniz. Buradaki örnegimizde okudugumuz okulu veya mezunlar için mezun oldukları okulu giris kabul edip cıkıs ekranında bunu yazdıracak basit bir uygulama yapacagız Figur penceresine 1 static text, 1 edit text ve birde push buton ekleyin ve asagıda görülen sekle getirin. Sekilde pembe olan static text sarı olansa girisi yapacagımız edit text mor olan ise push buton dur.

Page 27: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 27 31.10.2006

Bu sekle getirdikten sonra edit.fig olarak kaydedin ve acılan m-functon dosyasını asagıdaki gibi kodlayın. function varargout = edit(varargin) % EDIT Application M-file for edit.fig % FIG = EDIT launch edit GUI. % EDIT('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 18-Oct-2006 03:18:21 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch

Page 28: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 28 31.10.2006

disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = edit1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.edit1. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. a=findobj(gcbf,'TAG','edit1'); %etiketi edit1 olan nesneyi bul a ya ata b=findobj(gcbf,'TAG','text1'); %etiketi text1 olan nesneyi bul b ye ata yazi=get(a,'string') %a nın belirtiği nesnenin stringini yazi değikenin ata set(b,'string',yazi) %yazi ile belirtilen stringi b nesnesinin stringine ata

Page 29: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 29 31.10.2006

Programı calıstırıp edit texte okulunuzu yazıp butona tıklarsanız asagıdaki gibi bir görüntü elde edersiniz

SLIDER UYGULAMASI Slider 0 degeri ile baslayıp en son 1 degerini alan değisken deger giriş bandı olarak düsünülebilir.Örnekte 2 slider kullanılarak yol zaman degerleri girilerek hız bulan bir program yazalım. Bunun için figur yüzeyine 2 tane slider 6 tane static text yerleştirin.

Burada etiketleri sırasıyla static tex1 olan nesnenin stringine yol(km),static text 2 nin stringini bos bırakın static text3 ün stringine zaman(h) static tex4 stringini bos bırakın static text5 in stringine hız(km/s) yazın ve satic text6 yı bos bırakın. Ayrıca slider1 ile yol degerini slider2 ilede zamanı kontrol edecegiz.

Page 30: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 30 31.10.2006

Bu figuru slider.fig olarak kaydettiğinizde karsınıza cıkan m-function dosyasını asagıdaki sekilde kodlayın. function varargout = slider(varargin) % SLIDER Application M-file for slider.fig % FIG = SLIDER launch slider GUI. % SLIDER('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 18-Oct-2006 15:56:37 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %|

Page 31: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 31 31.10.2006

%| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = slider1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.slider1. durum=get(gcbo,'value'); as1=findobj(gcbf,'tag','text2'); set(as1,'string',durum*100); yol=get(as1,'string') as2=findobj(gcbf,'Tag','text4'); zaman=get(as2,'string'); yol=str2num(yol); zaman=str2num(zaman); hiz=yol/zaman; hiz=num2str(hiz); as3=findobj(gcbf,'tag','text6'); set(as3,'string',hiz); % -------------------------------------------------------------------- function varargout = slider2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.slider2. durum=get(gcbo,'value'); as1=findobj(gcbf,'tag','text4'); set(as1,'string',durum*10); zaman=get(as1,'string') as2=findobj(gcbf,'Tag','text2'); yol=get(as2,'string'); yol=str2num(yol); zaman=str2num(zaman); hiz=yol/zaman; hiz=num2str(hiz); as3=findobj(gcbf,'tag','text6'); set(as3,'string',hiz);

Page 32: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 32 31.10.2006

Kodları acıklayacak olursak slider1 için sliderin o anki degeri durum değişkenine atanıyor.Etiketi tex2 olan nesne as1 e atanıyor ve stringi durum degişkeninin aldıgı degerin 100 katı olacak sekilde değiştiriliyor. as1 stringi yol değişkenine atanıyor. Daha sonra etiketi tex4 olan nesne as2 değişkenine atanıyor.as2 nin stringide zaman değişkenine atanıyor.Burda bilinmesi gereken as2 stringinin slider2 ile değiştigidir. Matematiksel işlem yapacagımızdan yol ve zaman değişkenlerinin içeriklerini str2num fonksiyonu ile numerik formata ceviriyoruz. Hız=yol/zaman olarak yazdıktan sonra bulunan hız sonucunu tekrar karakter forma cevirmek için num2str fonksiyonunu kullanıyoruz. as3 değişkenine etiketi text6 olan static texti atıyoruz ve hız bilgisini string olarak bu değişkene atıyoruz.Programın son durumda calısması asagıdaki gibi olacaktır

LĐST BOX UYGULAMASI Listbox bir cok secenegi barındıran bir objedir.Amac listbox tan kulllanıcıcnın istediği secenege göre programa işlev kazandırmaktır. Örnek olarak biz burda kolay bir örnek olması bakımından meslegimizi ekrana yazacak bir uygulama yapalım Figur yüzeyimize 1 tane listbox ve 2 tane statick text yerlestirin ve etiketi text1 olan static textin stringini ‘MESLEGINIZ’ olarak degistirin.text2 olanı ise bos bırakın. Listbox a secenek girişi yapmak için,list box üzerine cift tıklayın ve özellikler menusunu acın. Asagıdaki sekilde görülen secenek ekleme dügmesine basın.

Page 33: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 33 31.10.2006

Karsınıza cıkan kücük pencerede listbox yazan satırı silin ve asagıdaki gibi secenekleri ekleyin.

Bu işlemlerden sonra OK dügmesine basarak özellikler penceresinide kapatın.Eklediğimiz seceneklerden Ögrenci olan secenek için listbox 1 degerini alır,muhendis için 2,polis için 3 degerlerini alarak ilerler.Bu nokta kodlamalar için önemlidir. Figur yüzeyimiz asagıdaki gibi olacaktır.

Page 34: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 34 31.10.2006

Bu işlemlerden sonra figurumuzu listbox.fig olarak kaydedinKarsınıza cıkacak olan m-function dosyasını asagıdaki gibi kodlayın. function varargout = listbox(varargin) % LISTBOX Application M-file for listbox.fig % FIG = LISTBOX launch listbox GUI. % LISTBOX('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 18-Oct-2006 16:52:17 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try

Page 35: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 35 31.10.2006

[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = listbox1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.listbox1. global sec sec=get(gcbo,'value')

Page 36: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 36 31.10.2006

x1=findobj(gcbf,'Tag','text2'); switch(sec) case 1, set(x1,'string','OGRENCI') case 2, set(x1,'string','MUHENDIS') case 3, set(x1,'string','POLIS') case 4, set(x1,'string','RADYOLOG') case 5, set(x1,'string','EV HANIMI') case 6, set(x1,'string','AVUKAT') case 7, set(x1,'string','HEMSIRE') end Kodlamada yapılan işlem listboxun aldıgı deger sec adlı değişkene atanıyor.Daha sonra sec adlı değişken bir switch döngüsüne sokuluyorak sec adlı değişkenin aldıgı degere göre etiketi text2 olan static texte yazılacak yazı secilmis oluyor.Programı calıstırdıgınızda asagıdaki görüntüyü elde edeceksiniz.

POPUP MENU UYGULAMASI Popup menude aynı listbox gibi birden cok secenekten birini secmek için kullanılır ve acılır menuye sahiptir.Listbox taki örnegimizin aynısını tekrarlayalım Figur yüzeyimize 1 tane popupmenu ve 2 tane statick text yerlestirin ve etiketi text1 olan static textin stringini ‘MESLEGINIZ’ olarak degistirin.text2 olanı ise bos bırakın. Ayrıca listboxta yaptıgımız işlemleri tekrar ederek popup menuye asagıdaki gibi meslek girişlerini yapın

Page 37: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 37 31.10.2006

Seciniz OGRENCI MUHENDIS POLIS RADYOLOG EV HANIMI AVUKAT HEMSIRE Seklinde meslekleri girin ve Ok tusuna basarak cıkın.Figur yüzeyimizin son görüntüsü asagıdaki gibi olacaktır.

Popup menude seciniz 1 degerini ogrenci 2 degeri alır ve en son secenege kadar böyle artan sırayla devam eder.Bu işlemleri yaptıktan sonra bu figürü popup.fig olarak kaydedin.Ekrana gelecek olan m-fuction dosyasını asagıdaki gibi kodlayın. function varargout = popup(varargin) % POPUP Application M-file for popup.fig % FIG = POPUP launch popup GUI. % POPUP('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 19-Oct-2006 02:16:11 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

Page 38: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 38 31.10.2006

% Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to:

Page 39: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 39 31.10.2006

%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = popupmenu1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.popupmenu1. global sec sec=get(gcbo,'value') x1=findobj(gcbf,'Tag','text2'); switch(sec) case 2, set(x1,'string','OGRENCI') case 3, set(x1,'string','MUHENDIS') case 4, set(x1,'string','POLIS') case 5, set(x1,'string','RADYOLOG') case 6, set(x1,'string','EV HANIMI') case 7, set(x1,'string','AVUKAT') case 8, set(x1,'string','HEMSIRE') end Bu kodlamada dikkat edilecek tek husus case yapısının 2 degerinden baslaması gerektiğidir.Nedeni seciniz 1 degerini alıyorken meslek isimleri 2 degerinden baslayarak artıyor.Đlk meslek olan ögrenci secenegi popup menunun 2 degerindedir. Geri kalan bütün kodlamalar listbox ile aynıdır. Programın görüntüsü asagıdaki gibi olacaktır.

Page 40: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 40 31.10.2006

AXES UYGULAMASI Axes programlarımızda eger cizim olusturulacaksa ve bu cizim program üzerinde görüntülenecekse kullanılır. Bir örnekle axes in kullanılmasını ve bazı kurallarını görelim. Figür penceresine bir push buton ve bir tane axes nesnesi yerleştirin Push butonun stringine ‘CIZ’ yazın. Axes cizim nesnesi ile matlabta gerceklestirdiğiniz 2 veya 3 boyut tüm cizimleri gerceklestirmeniz mümkündür.Eger axes özelliklerini incelerseniz her x,y ve z düzleminde istediğiniz tüm ayarlamaları eksen etiketleme ,eksenleri ayarlama gibi bir cok işlemi gerceklestimeniz mümkündür.Her düzlem için farklı ayarlamaları yapmak için axes özellik penceresinde x y z eksenlerine ait özellikler farklı seceneklerle görülmektedir. Bilinmesi gereken bir diger nokta eger ciziminizin yeni bir pencerede acılmasını istemiyor sadece axes üzerinde görülmesini istiyorsanız figur yüzeyine cift tıklayıp figur yüzeyi özelliklerinden HANDLEVĐSĐBĐLĐTY secenegini ON durumuna getirin.Asagıda bu özelligi nasıl on durumuna getireceginiz anlatılıyor. Bunun için figur yüzeyine çift tıklayın ve acılan özellikler penceresinden Handlevisibility yanındaki kücük tusa tıklayın ve ‘on’ secenegini secin ve enterlayıp pencereyi kapatın. Böylece cizimler programda yeni pencere acılmadan yüzey üzerinde görülecektir. En son görüntümüz asagıdaki gibidir.

Bu işlemlerden sonra figürü axes1.fig olarak kaydedin ve acılan m-function dosyasını asagıdaki gibi kodlayın.

Page 41: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 41 31.10.2006

function varargout = axes1(varargin) % AXES1 Application M-file for axes1.fig % FIG = AXES1 launch axes1 GUI. % AXES1('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 20-Oct-2006 01:33:38 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using

Page 42: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 42 31.10.2006

%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. global t global x t=0:1:5; x=t*5+10; plot(t,x) Kodlama da t 0 dan baslayıp 5 e kadar 1 er aralıklarla degerler alıyor.x ise t ye baglı degişen bir değişken.Cizim ekranında t ye göre x cizdirilmiştir. Programı calıstırıp cız butonuna basarsanız asagıdaki ekran görüntüsünü alacaksınız

Page 43: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 43 31.10.2006

STATĐC TEXT ve FRAME Statict text program cıktılarının görülecegi veya program üzerinde yazılacak yazının görüntülenmesini saglayacaktır.Bunun için static textin string secenegi kullanılır.Örnek uygulamalarda görülüyor. Frame ise cercevedir.Belli bir nesne grubunu bir arada görülmesini saglamak için kullanılır.Static text ve Frame için kodlama dosyasında callback işlemi bulunmaz.

Page 44: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 44 31.10.2006

MATLAB GUI DE ETKĐLESĐM KUTULARI Programcı olusturdugu programlarda kullanıcıyı bilgilendirmek veya program hatası gibi durumlarda kullanıcıyı uyarmak durumundadır.Ayrıca programda kullanıcının isteklerine veya sorularına cevap olusturması bakımından bazı etkileşim kutularını programa eklemelidir.Bu bölümde bu etkileşim kutuları ele alınacaktır. Etkileşim kutuları 2 kısımda incelenir.Bunlardan ilki ‘modal’ tipli olanıdır.Modal tipli etkileşim kutularında kullanıcının programa dönebilmesi için etkileşim kutusundaki bazı işlevleri yerine getirmek zorundadır.Bu tiplerden ikincisi ise ‘nonmodal’ tipli etkileşim kutusudur.nonmodal etkileşim kutularında ise kullanıcı etkilesim kutusunda bir işlev yapmaksızın programa dönebilir Programlarda kullanabileceginiz etkilesim kutularından bazıları sunlardır. Etkileşim Kutusu Đsimleri Acıklamaları errordlg Hata penceresi helpdlg Yardım penceresi inputdlg Veri giriş penceresi questdlg Sorgu penceresi Warndlg Uyarı penceresi Msgbox Mesaj iletim kutusu Waitbar Yükleme çubugu Listdlg Liste görünüm penceresi Printdlg Yazdırma penceresi Uigetfile Dosya acma penceresi Uiputfile Dosya kaydetme penceresi Uisetcolor Renk secim penceresi Uisetfont Karakter tipi penceresi Pagesetupdlg Sayfa yapısı penceresi printpreview Sayfa önizleme penceresi HATA PENCERESĐ(errordlg) Program icrası durumunda programda herhangi bir hata geldiğinde kullanıcıyı hata yönünden bilgilendirmeye yarayan penceredir. Kullanılışı; errordlg(‘pencerede görülecek yazı’,’pencere baslıgı’,’pencere özellik tipi’) seklindedir. Bu pencere için try catch end hata bulma akısından yararlanılır. try %buraya… %programlama kodları… %yazılır. catch errordlg(‘pencerede görülecek yazı’,’pencere baslıgı’,’pencere özellik tipi’) end seklinde kullanılır.

Page 45: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 45 31.10.2006

YARDIM PENCERESĐ(helpdlg) Program işleyişi esnasında kullanıcıya yardım belirtmek için kullanılan penceredir. Kullanılısı; helpdlg(‘pencerede görülecek yazı’,’pencere baslıgı’) UYARI PENCERESĐ(warndlg) Programın işleyişi esnasında meydana gelebilecek durumlar için kullanılır. Kullanılısı; warndlg(‘pencerede görülecek yazı’,’pencere baslıgı’,’pencere özellik tipi’) Bir örnek ile bu 3 pencerenin görünüsünü görelim. Bir figur yüzeyine 3 tane push button yerlestirip etiketi pushbutton1 olan buton stringine ‘HATA GOSTER’ etiketi pushbutton2 olan buton stringine ‘YARDIM GOSTER’ ve etiketi pushbutton3 olan butonun stringinede ‘ UYARI GOSTER’ seklinde yazın.Figürümüz asagıdaki sekilde belirecektir.

Bu figuru pencere.fig olarak kaydedip acılan m-function dosyasını asagıdaki gibi kodlayın. function varargout = pencere(varargin) % PENCERE Application M-file for pencere.fig % FIG = PENCERE launch pencere GUI. % PENCERE('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 20-Oct-2006 20:55:32 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

Page 46: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 46 31.10.2006

% Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))

Page 47: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 47 31.10.2006

%| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. errordlg('hatali yanlis deger girdiniz','hata','modal') % -------------------------------------------------------------------- function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton2. helpdlg('yardim edelim','yardim') % -------------------------------------------------------------------- function varargout = pushbutton3_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton3. warndlg('tehlikeli bir durum olustu','tehlike','nonmodal') Programı calıstırıp butonlara sırayla tıklarsanız ilgili pencerelerin acıldıgını göreceksiniz. Program calısırken 2 noktaya dikkat etmeniz gerekir ilki hata penceresi acıldıgında hata penceresindeki OK butonuna basmadan programa tekrar dönüs saglayamazsınız.Bunun nedeni hata penceresinin ‘modal’ tipli kodlanmıs olmasıdır.Đkincisi ise tehlike penceresi acıldıgında Ok tusuna basmasanızda programa dönüs saglayabilirsiniz bunun nedenide tehlike penceresinin ‘nonmodal’ olarak kodlanmasıdır.Program calıstırılıp hata butonuna basarsanız asagıdaki görüntüyü elde edeceksiniz

MESAJ PENCERESĐ(msgbox) Programın içleyisi esnasında kullanıcıya mesaj vermek için kullanılır.Mesaj penceresinin bir kac türlü kullanımı mevcuttur.Bunlar msgbox(‘mesaj’) msgbox(‘mesaj’,’baslık’) msgbox(‘mesaj’,’baslık’,’ikon’)

Page 48: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 48 31.10.2006

msgbox(‘pencerede görülecek yazı’,’pencere baslıgı’,’custom’,resim datası,resim renk haritası) seklinde kullanısları mevcuttur. ‘ikon’ msgbox penceresinde görüntülenecek olan resmi belirtir(örn; help) seklinde olabilir. Resim datası ve resim renk haritası ise calısma klasorunuzde olan resim dosyasının pencerede gösterilmesi için kullanılır. En son olusturulan pencere.m kod dosyasındaki yardım göster butonunun stringini mesaj goster olarak degiştirin ve buton kodunu msgbox(‘HOSGELDINIZ’,’mesaj’) ile değiştirip aynı sekilde calıstırdıgınızda mesaj kutusunun calısmasını görebilirsiniz.Mesaj kutumuz su sekilde olusacaktır.

VERĐ GĐRĐŞ PENCERESĐ(inputdlg) Program işleyişi esnasında kullanıcıdan veri almak için kullanılan etkileşim kutusudur. Kullanılısı Veri_matrisi=inputdlg(sorular_matrisi,’pencere baslıgı’,satır_sayısı,’baslangıc_degerler’) seklindedir Sorular matrisi bir satır matrisi olup pencere soru sayısı kadar satır içerir. Sorular_matrisi={‘soru1’,’soru2’,………’soru n’} seklindedir Satır sayısı pencerede bulunacak girdi satır sayısını gösterir.(yani verinin girilecegi text ekranının büyüklügünü ayarlar) Baslangıc_degerler ise eger sorulara baslangıcta pencerede görülecek bir deger verilmek isteniyorsa bu degerleri içerir. Veri_matrisi ise kullanıcının verdiği yanıtları içeren matristir. Uygulamada kullanıcının ismini yasını ve meslegini isteyecegiz.Bunun için Figur penceresine tek bir buton yerlestirip stringine ‘sorgula’ yazın.Daha sonra figürümüzü sorgula.fig olarak kaydedip karsınıza cıkan m-function dosyasını asagıdaki kodlamayı yapın. function varargout = sorgula(varargin) % SORGULA Application M-file for sorgula.fig % FIG = SORGULA launch sorgula GUI. % SORGULA('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 21-Oct-2006 01:01:48

Page 49: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 49 31.10.2006

if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see

Page 50: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 50 31.10.2006

%| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. sorular={'ISIM','YAS','MESLEK'} baslangic={'','',''}; pencere='cevaplayiniz'; alinan_veri=inputdlg(sorular,pencere,1) Programı calıstırıp ve butona tıklardıgınızda baslangıc verileri bos oldugundan satırların bos oldugu görülecektir Pencere baslıgımız ‘cevaplayiniz’ yazmaktadır.

Veri girişi olarak harun 23 elektrik elektronik mühendisi seklinde veri girip ok e bastıgımızda alinan_veri değişkeni asagıdaki gibi deger alır. alinan_veri = 'harun' '23' 'elektrik elektronik mühendisi'

Page 51: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 51 31.10.2006

SORGU PENCERESĐ(questdlg) Sorgu penceresi program işleyisi sırasında kullanıcıdan belirli seceneklerden birini secmesini istemek üzere kullanılan etkilesim kutusudur. Kullanılısı Sorgu=questdlg(‘soru’,’pencere baslıgı’,’cevap1’,’cevap2’,’cevap3’,’varsayılan’) seklindedir. Soru pencerede görülen yazıdır, Cevap1……cevap3 ise kullanıcıdan birini secmesini istediğimiz cevaplar Varsayılan kullanılabilir varsayılan degerdir.Bu deger pencerede kalın yazı ile belirtilir. Bunun için figür yüzeyine bir buton yerlestirip stringine ‘sorgu’ yazıp figuru sorgupen.fig olarak kaydedin.karsınıza cıkan m-function dosyasını asagıdaki gibi kodlayın. function varargout = sorgupen(varargin) % SORGUPEN Application M-file for sorgupen.fig % FIG = SORGUPEN launch sorgupen GUI. % SORGUPEN('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 21-Oct-2006 20:57:54 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and

Page 52: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 52 31.10.2006

%| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. global sorgu sorgu=questdlg('giris degeri nedir?','giris degeri','5','10','15','5') Programı calısıtırıp butona bastıgınızda sorgu ekranı karsınıza gelecektir.5 yazan buton üzerine bakarsanız biz varsayılan 5 belirttiğimiz için bu butondaki yazının kalın yazıldıgını göreceksiniz.Üzerinde 10 yazan buton üzerine tıkladıgımızda sorgu degişkeninin aldıgı deger sorgu = 10 seklinde olcaktır. Programın en son hali asagıdaki gibi olacaktır.

Page 53: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 53 31.10.2006

LĐSTE GÖRÜNÜM PENCERESĐ(listdlg) Liste görünüm penceresi bir konumdaki dosyalar üzerinde görüntüleme acma ve kaydetme gibi özellikler tasır. Kullanımı; [s,v] = listdlg('PromptString','Select a file:',... 'SelectionMode','single',... 'ListString',str) seklindedir. Select a file kısmı pencere üzerinde görülecek yazıyı temsil eder. Single secme imkanını gösterir single�tekli secim multiple�coklu secim imkanı Str görüntülenecek matrisi belirtir. Örnek olarak calısma dizinimizdeki dosyaları gösterecegiz Figur yüzeyine bir tane buton ekleyip stringini dosyaları göster yazarak Liste.fig olarak kaydedip acılan m-function dosyasını asagıdaki gibi kodlayın function varargout = liste(varargin) % LISTE Application M-file for liste.fig % FIG = LISTE launch liste GUI. % LISTE('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 21-Oct-2006 21:31:33 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles);

Page 54: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 54 31.10.2006

if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis.

Page 55: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 55 31.10.2006

% -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. d = dir; str = {d.name}; [s,v] = listdlg('PromptString','dosya goster',... 'SelectionMode','single',... 'ListString',str) Kodlamayı acıklarsak d=dir komutu calısma dizinimizdeki dosya ve klasörlerin yapı matrislerini d değişkenine atıyoruz. Str={d.name} komutu ise d matrisinin temsil ettiği tüm eleman isimlerinden olusan matris olusuyor [s,v] = listdlg('PromptString','dosya goster',... 'SelectionMode','single',... 'ListString',str) komutu ile tek secim imkanı saglanmıs pencere üzerinde dosya göster yazısı belirlenmis ve secilen herhangi bir eleman bir elemanın sırasıyla sutun degeri s degişkenine satır degeride v değişkenine aktarılmıstır. Bu noktada matlabın azizliğine ugradıgım(pencerede sorun oldugundan görüntülenemedi) için size sadece programın calısmasını anlattım. Ayrıca matlabtan kopyala yapıstır yapmıs dememeniz içinde yazdıgımız kodları asagıdaki gibi değiştirirseniz bilgisayarınızdaki D: partition nundaki dosyaları görüntüleyebileceginizi göstermek isterim. cd d: m=dir str = {m.name}; [s,v] = listdlg('PromptString','dosya goster',... 'SelectionMode','single',... 'ListString',str) Buradaki kodlamada ise d: partitionu içerisine giriyoruz ve m değişkeni ise D: partitionu içerisinde bulunan dosya ve dizinlerin yapı matrisini temsil eder. YAZDIRMA PENCERESĐ(printdlg) Figürü yazdırma işlemi gerceklestirilnek istendiğinde kulllanılan etkileşim kutusudur. Kullanılısı: Printdlg Veya Printdlg(‘-setup’) seklindedir. Figur yüzeyine bir buton ekleyip stringini YAZDIR olarak değiştirin ve figürü yaz.fig olarak kaydedin acılacak m-function dosyasını asagıdaki gibi kodlayın.

Page 56: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 56 31.10.2006

function varargout = yaz(varargin) % YAZ Application M-file for yaz.fig % FIG = YAZ launch yaz GUI. % YAZ('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 21-Oct-2006 23:14:13 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using

Page 57: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 57 31.10.2006

%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. printdlg('-setup') Kodlama yapılırken sadece printdlg yazılması durumunda ise acılacak yazdırma penceresinde değişim söz konusu olcaktır. Programı bu sekilde calıstırıp YAZDIR butonuna tıkladıgınızda asagıdaki görüntüyü elde edersiniz.

Not:Burada gözüken yazıcı olmayıp pdf dosya ceviricisinin sanal yazıcısı gözüküyo .Eger yazıcınız baglı ise burada görebileceksiniz.

Page 58: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 58 31.10.2006

RENK SECĐM PENCERESĐ(uisetcolor) Programın calısması esnasında kullanıcının isteği dogrultusunda figur ile ilgili bir yüzeyin renk değişimi saglanmak istenirse kullanıcının renk secebilecegi renk secme diyalog kutusudur. Kullanısı; Uisetcolor Figurde bulunan bir static text yüzeyinin background unu kullanıcının isteği dogrultusunda değiştirelim. Bunun için figür yüzeyine bir static text ve bir tanede buton yerlestirin. Static text stringini silin ve buton stringinede RENK DEGISTIR yazın. Figurü renksec.fig olarak kaydedip acılan m-function dosyasını asagıdaki gibi kodlayın. function varargout = renksec(varargin) % RENKSEC Application M-file for renksec.fig % FIG = RENKSEC launch renksec GUI. % RENKSEC('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 21-Oct-2006 23:31:45 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end

Page 59: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 59 31.10.2006

%| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. global d d=uisetcolor a=d(1,1) b=d(1,2) c=d(1,3) str1=findobj(gcbf,'TAG','text1') set(str1,'backgroundcolor',[a,b,c]) Programı calıstırıp butona tıkladıgınızda karsınıza renk secim penceresi acılacaktır.Bu renk secim penceresinden fare ile herhangi bir renk secip ok butonuna basarsanız d 1x3 lük bir vektör matrisi seklinde 3 deger alacaktır.Bu degerlerin her birini biz bir değişkene atıyoruz.

Page 60: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 60 31.10.2006

str1=findobj(gcbf,'TAG','text1') set(str1,'backgroundcolor',[a,b,c]) ile figürde static text i bulup set komutu ile background degerlerine a,b ve c degerlerini atıyoruz.Boylece renk değişimi saglanmıs oluyor ve static textin rengi istediğimiz renk olarak değişmiş oluyor Program calıstırıldıgında static texle figür yüzeyi aynı renge sahip oldugundan görülmemektedir.Son durumda acılan ekran asagıdaki gibidir

KARAKTER TĐPĐ PENCERESĐ(uisetfont) Kullanıcının istegi dogrultusunda programda kullanılan stringleri sekillendirmeye yarar. Kullanılısı; Uisetfont seklindedir. Figür yüzeyimize bir tane statict text ve bir tanede buton yerlestirip static text stringini UC KURUSLUK SEVGIYE BES KURUS DEGER VERIRSEN ARTA KALAN IKI KURUSA SATILIRSIN yazın.(Bu fırıncı abimizin sözü sagaolsun burda kullandık.) Buton içinde DUZENLE yazın Static textin boyutunu uzun ve geniş tutarsanız ayarlamalar sonucu ekranda bütün yazıyı görebilirsiniz Bu dosyayı ayarla.fig olarak kaydedip karsınıza cıkan m-function dosyasını asagıdaki gibi kodlayın function varargout = ayarla(varargin) % AYARLA Application M-file for ayarla.fig % FIG = AYARLA launch ayarla GUI. % AYARLA('callback_name', ...) invoke the named callback.

Page 61: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 61 31.10.2006

% Last Modified by GUIDE v2.0 22-Oct-2006 00:14:04 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure

Page 62: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 62 31.10.2006

%| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. duzen=uisetfont str=findobj(gcbf,'TAG','text1') set(str,duzen) Program calıstırılıp duzenle butonuna basarsanız karakter tipi penceresi karsınıza cıkacaktır. Burada yaptıgınız ayarlamalar----benim yaptıgım Yazı tipi�Arial Yazı tipi stili�Kalın ve Boyut�12--- sonucunda duzen degıskenının alacagı degerler asagıdakı gıbıdır. duzen = FontName: 'Arial' FontUnits: 'points' FontSize: 12 FontWeight: 'bold' FontAngle: 'normal' Bu duzen adlı değişken içeriği set komutu ile static textin stringine uygulanıyor.Böylece istenen yazı tipi saglanmıs oluyor.Programı calıstırılıp butona basıldıgında asagıdaki gibi görünecektir.Đstenen secimleri yapıp Ok e tıklarsanız yazıdaki değişiklikleri görebilirsiniz.

Page 63: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 63 31.10.2006

SAYFA YAPISI PENCERESĐ(pagesetupdlg) Bu etkileşim kutusu cıktısı alınacak belgelerin veya sekillerin sayfa üzerindeki yerleşimlerini ve sayfa yapılarını kontrol etmek için kullanılır. Kullanılısı; Pagesetupdlg Seklindedir. Figür yüzeyimize bir tane buton yerlestirip stringini sayfa yapısı olarak değiştirin ve figürü sayfa.fig olarak kaydedip acılan m-function dosyasını asagıdaki kodlayın function varargout = sayfa(varargin) % SAYFA Application M-file for sayfa.fig % FIG = SAYFA launch sayfa GUI. % SAYFA('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 22-Oct-2006 00:58:13 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor'));

Page 64: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 64 31.10.2006

% Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))

Page 65: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 65 31.10.2006

%| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. pagesetupdlg Programı calıstırıp butona tıkladıgınızda asagıdaki ekran görüntüsünü alısınız

YÜKLEME ÇUBUGU (waitbar) Yukleme cubugu genelde butun programlarda kullanılan ve o sırada yukleme yapıldıgını ve yukleme durumunu gosteren cubuktur. Kullanılısı; h = waitbar(0,'Please wait...'); for i=1:100, % acılıs işlemleri % waitbar(i/100) end close(h)

Page 66: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 66 31.10.2006

Bu noktadada matlabın azizligine ugradıgım için yukarıda yazılan programı yükleme sırasında işleyecek sekilde eklerseniz yükleme cubugu calısmasını gerceklestirecektir. SAYFA ÖNĐZLEME PENCERESĐ(printpreview) Cıktısı alınacak belgenin sayfa üzerinde nasıl görüldügünü gösteren etkileşim penceresidir. Kullanılısı; Printpreview seklindedir Ayrıca bu pencere sayfa yapısı penceresinide(page setup) içermektedir Görüntüsü asagıdaki gibidir.

Page 67: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 67 31.10.2006

DOSYA KAYDETME PENCERESĐ(uiputfile) Dosya kaydetme pencereleri genellikle program menülerinden dosya menüsü altında bulunur. Bu etkileşim kutusu yardımıyla dosya program üzerinden kaydedilebilmektedir. Matlabta program kaydetme komutu save komutudur. Kullanılısı [fname,pname] = uiputfile('*.dosya uzantısı','pencere baslıgı') seklindedir. Fname :dosya adı Pname :dosya yolu Temsil ederler. Bu işlemler sadece acılacak pencerede kayıt uzantısını ve ve pencere baslıgı belirtilmiştir. Kayıt işleminin gerceklesebilmesi için gerekli olan komut satırı asagıdaki gibidir. [fname,pname] = uiputfile('*.dosya uzantısı','pencere baslıgı') if fname ~=0 save([pname fname]) end seklinde olmalıdır. Programı calırtırıp bütün matlab dosya uzantılarıyla birlikte acılan bir kaydetne pencresi acmak için [fname,pname]=uiputfile(... {'*m;*fig;*mat;*mdl','MATLAB DOSYALARI(*m,*fig,*mat,*mdl)'; '*.m','M-dosyalar(*.m)';... '*.fig','Figürler(*.fig)';... '*.mat','Mat-dosyalari(*.mat)';... '*.mdl','Modeller(*.mdl)';... '*.*','Tum dosyalar(*.*)'},... 'KAYIT ET'); if fname ~=0 save([pname fname]) end seklinde kullanınız. DOSYA ACMA KOMUTU(uigefile) Dosya acma pencereleri genellikle program menülerinden dosya menüsü altında bulunur. Bu etkileşim kutusu yardımıyla dosya program üzerinden acılabilir. Matlabta program load komutudur. Kullanılısı [fname,pname] = uigetfile('*.dosya uzantısı','pencere baslıgı')

Page 68: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 68 31.10.2006

seklindedir. Fname :dosya adı Pname :dosya yolu Temsil ederler. Bu işlemler sadece acılacak pencerede kayıtlı dosya uzantısını ve ve pencere baslıgı belirtilmiştir. Acma işleminin gerceklesebilmesi için gerekli olan komut satırı asagıdaki gibidir. [fname,pname] = uigetfile('*.dosya uzantısı','pencere baslıgı') if fname ~=0 load([pname fname]) end seklinde olmalıdır. Programı calırtırıp bütün matlab dosya uzantılarıyla birlikte acılan bir dosya acma pencresi acmak için [fname,pname]=uigetfile(... {'*m;*fig;*mat;*mdl','MATLAB DOSYALARI(*m,*fig,*mat,*mdl)'; '*.m','M-dosyalar(*.m)';... '*.fig','Figürler(*.fig)';... '*.mat','Mat-dosyalari(*.mat)';... '*.mdl','Modeller(*.mdl)';... '*.*','Tum dosyalar(*.*)'},... 'DOSYA AC'); if fname~=0 load([pname fname]) end seklinde kullanınız. Not:Dosya acma ve dosya kaydetme pencerelerinde sorun yasadıgımı belirtmek isterim.Buradaki kodları daha önce calıstırdıgım için sizin bu sorunu yasayacagınızı sanmıyorum.Yinede kodları yazıp yazmamak size kaldı bu noktada. SAAT VE TARĐH YAZDIRMA Programda kullanmak isteyebileceginiz bir diger noktada saat veya tarih olabilir.Matlabta saat ve tarih bulmak için asagıdaki 3 komuttan yararlanılır Date � Tarih bilgisini string olarak verir Clock �saat ve tarih bilgisini nümerik matris olarak verir [yy aa gg ss dd ss] Now�Tarih ve saat bilgisini nümerik deger olarak verir Bu noktada bize gerekli olan now komutudur. Now komutu sonucunda matlabın verecegi deger >> t_s=now

Page 69: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 69 31.10.2006

t_s = 7.3298e+005 seklinde olmaktadır.Bu nümerik degeri stringe cevirmek için datestr() komutundan yararlanılır.datestr() komutunun kullanılısı datestr(degişken,dateform) seklinde olmaktadır. Degişken tarih ve saatin atandıgı değişken Dateform ise tarih ve saati ekrana yazdırma biçimidir.Bu formatlar toplam 28 adet olup asagıdaki gibidir DATEFORM number DATEFORM string Example 0 'dd-mmm-yyyy HH:MM:SS' 01-Mar-2000 15:45:17 1 'dd-mmm-yyyy' 01-Mar-2000 2 'mm/dd/yy' 03/01/00 3 'mmm' Mar 4 'm' M 5 'mm' 03 6 'mm/dd' 03/01 7 'dd' 01 8 'ddd' Wed 9 'd' W 10 'yyyy' 2000 11 'yy' 00 12 'mmmyy' Mar00 13 'HH:MM:SS' 15:45:17 14 'HH:MM:SS PM' 3:45:17 PM 15 'HH:MM' 15:45 16 'HH:MM PM' 3:45 PM 17 'QQ-YY' Q1-96 18 'QQ' Q1 19 'dd/mm' 01/03 20 'dd/mm/yy' 01/03/00 21 'mmm.dd,yyyy HH:MM:SS' Mar.01,2000 15:45:17 22 'mmm.dd,yyyy' Mar.01,2000 23 'mm/dd/yyyy' 03/01/2000 24 'dd/mm/yyyy' 01/03/2000 25 'yy/mm/dd' 00/03/01 26 'yyyy/mm/dd' 2000/03/01 27 'QQ-YYYY' Q1-1996 28 'mmmyyyy' Mar2000 son buldugumuz t_s tarih ve saat değişkeni için string cevrimini 0 formatıyla yaparsak >> tarih_saat=datestr(t_s,0) tarih_saat = 31-Oct-2006 10:56:45 sonucunu elde ederiz.

Page 70: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 70 31.10.2006

Bu işlemlere göre GUI de hazırladıgınız herhangi program için static text in stringine bu en son buldugmuz tarih_saat adlı değişkeni atamanız yeterli olacaktır.Fakat bu deger anlık degerler oldugu için saat üzerinde saniye akısı göstermek mümkün değildir. Bir While-end döngüsüyle bu problem cözülebilsede bu noktada diger nesnelere ulasım engelleneceginden saniye akısını göstermek pek mümkün olmamaktadır.(tabi yapabilen biri varsa anlatırsa sevindirici olur) PROGRAMA SES EKLEME Olusturulan programa wav uzantılı ses dosyaları eklemek mümkündür.Ayrıca program üzerinde herhangi bir durumda uyarı amaclı beep seside eklenebilir Bunun için program kodları yazılırken gerekli görülen yerlere beep komutunun yazılması yeterli olacaktır Programda wav uzantılı bir dosyanın calmasını saglamak içinse sound() komutundan yararlanılır. Örnek bir programla programımıza saat,tarih gösterimi ve programa seslerin eklenmesi durumunu görelim. Bunun için gui figür yüzeyimize 2 pushbutton ve 1 tanede static text ekleyin ve asagıda görülen sekilde olusturun.

Bu noktadan sonra herhangi bir wav uzantılı müzik dosyasını work klasörünü kopyalayın.Burada örnegin ben bir yabancı sarkı dosyasıda ekledim ve bu sarkıyı 10 sn caldırabildim.Bunuda göz önünde bulundurursanız programa daha canlı sesler ekleme sansınız olabilir. Fakat biz C:\WINDOWS\Media\ Windows XP Başlangıç.wav dosyasını kopyalayıp work klasorüne yapıstırıyoruz.Bu arada bu work klasöründeki bu dosyanın ismini winxp.wav olarak değiştirin.Nedeni matlabın ş ve ç seslerini tanımayacagıdır. Bu işlemleri yaptıktan sonra programımıza dönelim.

Page 71: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 71 31.10.2006

Pushbutton1 in string kısmına ‘saat_tarih’ yazın Puhbutton2 nin string kısmınada ‘cal’ yazın ve uygulama1.fig olarak figürümüzü kaydedin karsınıza cıkacak m-function dosyasını asagıdaki gibi kodlayın function varargout = uygulama1(varargin) % UYGULAMA1 Application M-file for uygulama1.fig % FIG = UYGULAMA1 launch uygulama1 GUI. % UYGULAMA1('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 31-Oct-2006 11:52:41 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %|

Page 72: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 72 31.10.2006

%| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. global s_t global saat_tarih global str1 s_t=now; saat_tarih=datestr(s_t); str1=findobj(gcbf,'TAG','text1') set(str1,'string',saat_tarih) % -------------------------------------------------------------------- function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton2. [y,Fs,bits] = wavread('winxp'); sound(y,Fs,bits) program calıstırıldıgında istenilen butona basıldıgında işlemlerin gerceklestirildiği görülecektir.

Page 73: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 73 31.10.2006

PROGRAMA RESĐM EKLEME Programın çalışması esnasında program üzerinde bir resmin görüntülenmesi isteniyorsa bu resmin bu resmin matlar dosyası olarak kayıt edilmesi ve programa yüklenmesi gerekir. Bir resmin mat dosyası olarak kaydedilmesi için loadimage.m matlap m-dosyasının calısma dizinimizde bulunması gerekir. Loadimage.m dosyasını www.matworks.com adresinden MATLAB Central > File Exchange > Utilities > Graphics Import/Export > Saveimage-Loadimage yolu izlenerek veya tam adres satırı olarak http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=2395&objectType=file adresinden bilgisayarınıza cekebilirsiniz. Loadimage.m dosyasının içeriği asagıdakıi gibidir.Bu içeriği bir m-dosyaya yazıp ismini loadimage.m olacak sekilde calısma dizinine kaydetmenizde yeterli olacaktır. M-function dosyası; function [I,map]=loadimage [file,pathname]=uigetfile('*.*','Image'); buffer=pwd; cd (pathname); [I,map]=imread(file); cd (buffer); Programımıza ekleyecegimiz resim asagıdaki yakısıklı yegenimin magazadan bana bisiklet aldırma cabalarını gösteren resimdir.

Bu resmi matlab\work klasörüne kopyalayın.(veya herhangi bir resmi) Matlab komut satırında >>r=loadimage komutunu verin.Acılacak pencereden resmi bulun ve ac butonuna basın böylece komut satırında sayılar akmaya baslayacak biraz beklerseniz sayı akısı duracaktır.Bu durumda resim r matrisine atanmıs olcaktır. Komut satırında

Page 74: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 74 31.10.2006

>>save resim.mat r komutunu vererek resmi kaydetmiş olacaksınız. Work klasorüne bakarsanız resim.mat seklinde bir dosya olustugunu göreceksiniz. Komut satırında >>image(r) komutunu verirseniz resmi görüntüleyebilirsiniz.. Bir figür yüzeyi acarak 1 tane axes nesnesi ekleyin figür yüzeyi özelliklerinden Handlevisibilitiy secenegini ‘on’ konumuna getirin(yukarıda bu anlatılmıstır.) ve figürü resim.fig olarak kaydedin karsınıza cıkacak m-function dosyasını asagıdaki gibi kodlayın. function varargout = resim(varargin) % RESIM Application M-file for resim.fig % FIG = RESIM launch resim GUI. % RESIM('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 22-Oct-2006 20:47:23 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end %| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %|

Page 75: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 75 31.10.2006

%| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. load resim.mat image(r) programı calıstırdıgınızda ekranda resmi göreceksiniz fakat resimin alt ve sol tarafında ölceklendirme cetvelleri vardır.Bu cetvellerin görülmesini önlemek için frame kullanacagız. Figür yüzeyinize geri dönun ve 2 adet frameyi asagıda görüldügü gibi yerlestirip backgroundcolor ve ForegroundColor renklerini figür yüzeyinin background rengiyle aynı yapın.Varsayılan için sadece framenin ForegroundColor sekmesini tıklayın ve renkleri 87,87,89 yapın böylece framenin kenar renkleride figür yüzeyi ile aynı renkte olacaktır.

Page 76: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 76 31.10.2006

Bu dosyayı kaydet iconuna tıklayarak kaydedin ve programı tekrar calıstırdıgınızda asagıdaki görüntüyü alacaksınız

Eger frameleri cetvellerin üstüne tam oturtmamıs iseniz figüre tekrar dönüp framelerin en ve boyunu arttırarak cetvellerin görüntülenmesinin önüne gecilebilirsiniz.

Page 77: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 77 31.10.2006

PROGRAMLARA MENU EKLENMESĐ VE OLUSTURULMASI Olusturan programlara 2 sekilde menü yerleştirebilirsiniz.Bunun ilki matlab arayüzün kendi figür menüsüdür.Bunun için en son yapılan figürü acın ve figür yüzeyine cift tıklayıp figür yüzeyi özelliklerini acın. Menubar sekmesinde ‘figure’ yi secin ve enterlayıp bu pencereyi kapatın.tekrar kaydetme butonuna basarak figürü kaydedin ve calıstırın.Bu durumda asagıdaki standart menü sü olan görüntüyü alacaksınız.

Đkinci olarak kendi menünüzü olusturmak istiyorsanız. Figür yüzeyini tekrar eski konumuna getirin(menübardan none secenegini secin). Figür penceremizde menü editor ikonuna basarak aagıdaki gibi menü editor penceresini acın

Page 78: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 78 31.10.2006

Görülen New Menu secenegine tıklayın..Karsınıza untitled seklinde menü olusacak bu yazı üzerine tıklarsanız sag tarafta Uimenu Properties kısmı aktif olacaktır.Label kısmına ‘menu’ yazın. Daha sonra Bu dosya secenegi secili iken New menü ikonunun hemen sagındaki New Menü Đtem(alt secenk ekleme) ikonuna tıklayıp üntitled 2 seklinde alt menü olusturun bu menünün label kısmına sayfa yapisi yazın. Callback kısmına ise Pagesetupdlg yazın Üstteki dosya yazan kısmı fare ile secip tekrar New Menü item ikonuna tıklayın ve aynı sekilde bir menü daha olusturun.Bunun label kısmınada ‘sayfa önizleme’ yazın. Callback kısmına ise Printpreview yazın Aynı sekilde yine bir alt menü olusturup label kısmına ‘yazdır’ yazın.Bunun callback kısmınada Printdlg yazın. En son görüntü asagıdaki gibi olacaktır.

Page 79: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 79 31.10.2006

Label kısımlar programda görülen yazılardır. Bu işlemlerden sonra Tag (etiketleri labeller ile aynı olmayacak sekilde) belirtebilirsiniz Taglar menülerin etiketi lazım olacaksa kullanılır.Bizim burda kullanmamıza gerek yok. En önemli kısımlar callback kısımlarıdır. Buralarda gerekli olan etkileim kutularının kodlarının yazılması uygun olacaktır. Programa dönüs yapıp calıstırdıgınızda menü ikonuna tıklaranız asagıdaki görüntüyü alacaksınız

Page 80: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 80 31.10.2006

Menü olusturuken dikkat edilmesi gereken nokta menüleri derecesinegöre dallara ayırmaktır.Yani her üst menü bir agac ve bunlara baglı alt menüleride dallar olarak düsünmeniz uygun olacaktır. SAG TUS MENÜSÜ OLUSTURMA Sag tus menusu programın işleyişi sırasında kullanıcının farenin sag tusuna basarak yapacagı işlemleri gösteren menudur. Yukarıda menü olusturdugumuz figür için standart menü deki sayfa yapısı ,sayfa önizleme ve yazdir seceneklerini içeren sag tus menüsü düzenleyelim. Yukarıdaki figürü ele aldıgımızda Menu editor ikonundan yararlanarak menü editor penceresini acın ve alt kısımda görülen Context Menüs secenegine tıkladıgınızda asagıdaki ekranı göreceksiniz. Yeni bir sag tus menusu ismi tanımlayacaksınız bunun ismi Yazdırma secenekleri olsun.Bunun için new menüye tıklayıp uicontrol properties kısmında Tag kısmına yazdirma secenekleri yazın sonra bu menuye new menu item ikonu yardımıyla 3 altmenü ekleyin. Bunlardan Đlk alt menunun label kısmına sayfa yapisi yazın ve callback kısmına pagesetupdlg yazın Đkinci alt menunun label kısmına sayfa önizleme yazın ve callback kısmına pagepreview yazın Üçüncü alt menü için label kısmına yazdir yazın ve callback kısmına printdlg yazın Sag tus menümüz asagıdaki görüntü gibi olacaktır.

Page 81: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 81 31.10.2006

Page 82: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 82 31.10.2006

Menu olusturma işlemimiz bitmiş olacaktır. Figür yüzeyimize tekrar dönüp figür yüzey özellikleri penceresini acın ve uicontextmenü kısmından ‘yazdirma secenekleri ‘ yazan secenegi secin,

Bu secenek secildikten sonra özellikler penceresini kapatın ve figürü calıstırın.Ekran ortasında farenin sag tusuna tıklarsanız sag tus menumuz belirecektir. Bu noktada da sorun yasadıgımdan görüntüyü gösteremedim. GUĐ ĐLE .exe DOSYALARINI CALISTIRMA Arayüzde yapacagımız bir program ile istediğimiz herhangi bir exe uzantılı programı calıstırma imkanımız vardır. Bunun için örnek oalrak 3 buton ile farklı 3 exe uzantılı programı calıstıralım. Figür yüzeyimize 3 tane pushbutton ekleyip stringlerini asagıdaki görüntüde oldugu gibi değiştirin ve programı proac.fig olarak kaydedin.

Page 83: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 83 31.10.2006

Kaydetme işleminden sonra acılan m-function dosyasını asagıdaki gibi kodlayın function varargout = proac(varargin) % PROAC Application M-file for proac.fig % FIG = PROAC launch proac GUI. % PROAC('callback_name', ...) invoke the named callback. % Last Modified by GUIDE v2.0 22-Oct-2006 23:41:56 if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; end elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard catch disp(lasterr); end end

Page 84: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 84 31.10.2006

%| ABOUT CALLBACKS: %| GUIDE automatically appends subfunction prototypes to this file, and %| sets objects' callback properties to call them through the FEVAL %| switchyard above. This comment describes that mechanism. %| %| Each callback subfunction declaration has the following form: %| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN) %| %| The subfunction name is composed using the object's Tag and the %| callback type separated by '_', e.g. 'slider2_Callback', %| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'. %| %| H is the callback object's handle (obtained using GCBO). %| %| EVENTDATA is empty, but reserved for future use. %| %| HANDLES is a structure containing handles of components in GUI using %| tags as fieldnames, e.g. handles.figure1, handles.slider2. This %| structure is created at GUI startup using GUIHANDLES and stored in %| the figure's application data using GUIDATA. A copy of the structure %| is passed to each callback. You can store additional information in %| this structure at GUI startup, and you can change the structure %| during callbacks. Call guidata(h, handles) after changing your %| copy to replace the stored original so that subsequent callbacks see %| the updates. Type "help guihandles" and "help guidata" for more %| information. %| %| VARARGIN contains any extra arguments you have passed to the %| callback. Specify the extra arguments by editing the callback %| property in the inspector. By default, GUIDE sets the property to: %| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo)) %| Add any extra arguments after the last argument, before the final %| closing parenthesis. % -------------------------------------------------------------------- function varargout = pushbutton1_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton1. !C:\Program Files\Winamp\winamp.exe % -------------------------------------------------------------------- function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton2. !C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe % -------------------------------------------------------------------- function varargout = pushbutton3_Callback(h, eventdata, handles, varargin) % Stub for Callback of the uicontrol handles.pushbutton3. !C:\Program Files\AutoCAD 2004\acad.exe

Page 85: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 85 31.10.2006

Dosya yollarının önünde bulunan ! işareti komutun bir dos işletim sistemi komutu olarak algılanmasını saglayacaktır.Programı calıstırıp istediğiniz bir butona basarsanız programın acıldıgını göreceksiniz. MATLAB ĐLE DERLEME Matlab ile yaptıgınız figür dosyaları ve kodları yazdıgınız M-function dosyalarının.exe uzantılı icra edilebilir program dosyası haline getirmeniz gerekmektedir. Bunun için matlab kendi derleyicisi olan lcc derleyicisini kullanır. Matlab derleyici nin kullanılmasına ilişkin bilgileri matlab komut satırında >>help mcc yazarak bulabilirsiniz. Matlab Guı ile olusturulan programlar derlenirken 2 komut kullanılır. Bunlar 1->>mcc -B sgl dosyam.m 2->>mcc –B sglcpp dosyam.m Bu komutlar kullanırken 1. sekilde kullanılması durumunda c tabanlı grafik kutuphaneli uygulamalar olusur. 2. durumda ise c++ tabanlı grafik kütüphaneleri uygulamalar olusturulur. Derleme işlemi için hiç derleme işlemi yapmadıysanız asagıdaki adımları gerceklestirerek bu işlemi gerceklestirebilirsiniz. Adım1:>>mcc –B sgl dosyam.m Adım2: Please choose your compiler for building standalone MATLAB applications: Select a compiler: [1] Lcc C version 2.4 in C:\MATLABR12\sys\lcc [2] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio [0] None Compiler:1 �ENTER( burada bilgisayarda bulanan tüm derleyiciler sıralanır.Bu noktada bize LCC C versiyon derleyici gerekli oldugundan 1 yazıp enterlıyoruz.) Adım3: Please verify your choices: Compiler: Lcc C 2.4 Location: C:\MATLABR12\sys\lcc Are these correct?([y]/n):y (veya direk ENTER) Sorusuna y seklinde cevap verilir.Daha sonra matlab derleme işlemini gerceklestirecektir. Bu derleme işleminden sonra work klasorunde programınızın .exe uzantılı icra edilebilir dosyasını göreceksiniz

Page 86: Microsoft Word - Matlab Grafiksel Kullan

HARUN YALÇIN Sayfa 86 31.10.2006

Yorumlar: Buraya kadar anlatılan bilgilerle matlab grafiksel arayüzde bir programın nasıl olusturuldugunu anlattım. Programlamanın yapıldıgı m-functionları secilmeleri için mavi renk ile belirttim. Bazı konularda matlab 6 nın hezimetine ugrasamda eger siz gerekli komutları dogru yazarsanız programın dogru sekilde calıstıgını görecekseniz.Ayrıca bu sefer tek tek gözden gecirsemde belgedeki bol miktarda olan yazım yanlısları için kusura bakmayın. Kodlamalarda ise sorun yok. Bu arada kullandıgınız matlab sürümüne göre daha ceşitli etkileşim kutuları bulunmaktadır ve kodlamalar aynı olmasına ragmen kodlama yapılan m-function dosyaları değişik sekillerde içerikler olusturabilir. Bu döküman hazırlananırken hiçbir kaynaktan alıntı yapılmamıstır. Hepinize yardımcı olması dileklerimle saygılar. Đletişim [email protected]