matlab_gui_türkçe_kullanım_2012(güncel)

162
Matlab 7.0.1 GUI Tasarlama Harun YALÇIN 1 MATLAB 7.0.1 GUİ TASARIMI VE PROGRAMLAMA Hazırlayan: Harun YALÇIN Elektrik-Elektronik Mühendisi Elinizdeki bu doküman 2006 yılında yazmış olduğum Mablab GUI kullanıcı kılavuzu dökümanının şimdiye kadar ki geri bildirimlerde aldığım birkaç soruya cevap vermek ve öğrencilerin daha anlaşılır cümlelerle , bol örnekler ve çözümlerle işleyişi daha kolay kavramaları için geliştirilmiştir. Örnekler , anlatımlardan sonra örneklenmiştir. GUI (Grafiksel Arayüz) m-file ve m-fuction şeklinde yazılan dosyalardan oluştuğundan,Matlab Kütüphanelerinde bulunan tüm komutlar GUI de icra edilebilir durumdadır.Bu nedenle Matlab GUI programlamayı öğrenmeye başlamadan önce Matlab ile programlama öğrenilmesi GUI programlamada size yardımcı olacaktır. İnternet ortamında Matlab GUI ile ilgili bir çok Türkçe kaynak bulunmaktadır.Genel olarak burada anlatılanların aynısı anlatılmaktadır.Fakat burada örnekler üzerinde programların anlaşılabilmesi açısından farklı bir metod uygulanmıştır.Böylece örnekleri anlamanız kolaylaşacak ve tasarımınız için kendi fikirlerinizi daha kolay üretebileceksiniz. Program sürümü olarak 7.0.1 kullanılmasının sebebi,gelişen teknoloji ile büyüyen yazılım sektörünün her yıl yeni bir sürümü piyasaya sürerek ekonomik fayda sağlamalarından dolayı Matlab 6 nın üst sürümü olan 7.0.1 sürümünde tasarımı anlatarak elinizdeki en düşük Matlab sürümünde bile programlama yapabilmeniz açısındandır.Temel olarak aldığınız bilgiyi Matlab’ın üst sürümlerindede benzer şekilde veya uyarlayarak kullanmanız mümkündür. İlgili arkadaşlara şimdiden teşekkür ederim.

Upload: matador1071

Post on 28-Oct-2014

1.049 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 1

MATLAB 7.0.1 GUİ TASARIMI VE PROGRAMLAMA Hazırlayan: Harun YALÇIN Elektrik-Elektronik Mühendisi Elinizdeki bu doküman 2006 yılında yazmış olduğum Mablab GUI kullanıcı kılavuzu dökümanının şimdiye kadar ki geri bildirimlerde aldığım birkaç soruya cevap vermek ve öğrencilerin daha anlaşılır cümlelerle , bol örnekler ve çözümlerle işleyişi daha kolay kavramaları için geliştirilmiştir. Örnekler , anlatımlardan sonra örneklenmiştir. GUI (Grafiksel Arayüz) m-file ve m-fuction şeklinde yazılan dosyalardan oluştuğundan,Matlab Kütüphanelerinde bulunan tüm komutlar GUI de icra edilebilir durumdadır.Bu nedenle Matlab GUI programlamayı öğrenmeye başlamadan önce Matlab ile programlama öğrenilmesi GUI programlamada size yardımcı olacaktır. İnternet ortamında Matlab GUI ile ilgili bir çok Türkçe kaynak bulunmaktadır.Genel olarak burada anlatılanların aynısı anlatılmaktadır.Fakat burada örnekler üzerinde programların anlaşılabilmesi açısından farklı bir metod uygulanmıştır.Böylece örnekleri anlamanız kolaylaşacak ve tasarımınız için kendi fikirlerinizi daha kolay üretebileceksiniz. Program sürümü olarak 7.0.1 kullanılmasının sebebi,gelişen teknoloji ile büyüyen yazılım sektörünün her yıl yeni bir sürümü piyasaya sürerek ekonomik fayda sağlamalarından dolayı Matlab 6 nın üst sürümü olan 7.0.1 sürümünde tasarımı anlatarak elinizdeki en düşük Matlab sürümünde bile programlama yapabilmeniz açısındandır.Temel olarak aldığınız bilgiyi Matlab’ın üst sürümlerindede benzer şekilde veya uyarlayarak kullanmanız mümkündür. İlgili arkadaşlara şimdiden teşekkür ederim.

Page 2: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 2

HAKKIMDA: 2006 Fırat Üniversitesi mezunuyum.Askerlik hizmetimi gerçekleştirdikten sonra çeşitli işlerde çalıştım.Bu nedenle 46 adet ilde çalışmış olup değişik kültürler ve insanlar gördüm.Bunlar içerisinde sanayi tesisi , şantiye işleri mevcut olmakla birlikte şu anda bir elektrik dağıtım şirketinde Tesis kontrol mühendisi olarak çalışmaktayım. Bana ulaşmak isterseniz; [email protected] adresinden e-posta atabilirsiniz. www.harunyalcin.com adresinden gerekli iletişim bilgilerimi ve hakkımdaki bilgileri bulabilirsiniz.

Page 3: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 3

GİRİŞ Teknolojinin hızlı ilerlemesi sonucu büyük makinelerin küçüçük çiplere dönüşmesini sağladı.Bunun yanında daha akıllı cihazlar, sensörler, işlemleri mikrosaniyelerde yapan işlemciler, hareket algılayıcı kameralar ve birçok yazılımsal araç gelişti. Bu baş döndürücü teknolojinin arkasına saklanan 0 ve 1 leri kimse görmüyordu.Bunun yanında geçmişe baktığımızda bir yığın teknolojik çöp bırakıyoruz arkamızda.Bu bazen eski bilgisayarımız veya eski televizyonumuz oluyor. Bilgi aslında bileğimize taktığımız bilezikten daha çok ifade ediyor. GUI tasarlanan programların klavye ve fare yardımıyla son kullanıcıya, veriler aktarmaya yarayan programların tasarlanmasında kullanılmaktadır.Bu bazen basit bir hesap makinesi olabilir bazen bir balistik füzenin hedef bulmasına, bazende bir cerrahın hastasının kalp ritimlerini ekranda görmesine yarar. MATLAB GUI ÇALIŞMA PRENSİBİ GUI için ve grafiksel arayüzlü programlar için çalışma prensibi 3 aşamada incelenir. 1-GUI Yüzeyi (alt tema) 2-GUI Objeleri ( Programlanabilir Nesneler) 3-İşlevler (İcra edilen komutların bütünü) 1-GUI YÜZEYİ GUI yüzeyi , nesnelerin yerleşiminin sağlandığı,menülerin bir arada tutulduğu görsel temanın bir bütün halinde elde edildiği kısımdır. 2-GUI OBJELERİ GUI Objeleri , programın ana işlevinin kazandırılması için, her birinin kendine ait bir işlevi olan programın görsel işlevinide tamamlayan kısımdır.Buton,slider,axess vb… 3-İŞLEVLER Her bir nesnenin ne yapması gerektiğini ( program içindeki işlevsel mantığı) belirten kısımdır( CALLBACK).Matlab GUI her bir nesne için, nesnenin kendine ait olan işlevi otomatik olarak atamaktadır.Buda programcıya avantaj sağlamaktadır.

Page 4: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 4

GUI PENCERESİ ÖZELLİKLERİ GUI penceresi farklı şekilde çalıştırılabilir. 1-Komut satırında ‘’ guide ‘’ yazarak çalıştırılabilr. 2-FileNewGUI şeklinde çalıştırılabilir 3-StartMatlabGuide şeklinde çalıştırılabilir. Bu söz konusu 3 durumda da karşınıza gelecek ekran aşağıdaki şekilde olacaktır.

Burada bize 4 farklı seçenek sunulmaktadır.Her biri daha sonra kısaca anlatılmak üzere programcı olarak bize halihazırda olmayan Blank GUI(Default) seçeneği seçilmelidir.Bu secenek seçildikten sonra OK butonuna bastığınızda karşınız aşağıdaki gibi boş bir GUI programlama penceresi açılacaktır.

Page 5: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 5

Yukarıdaki resimde pencere yüzeyinde yer alan butonların işlevleri görülmektedir. Bu butonların ve eklentilerin işlevleri aşağıda açıkalnmıştır. Standart Menü New Yeni bir figür aç Open Kaydedilmiş figürü aç Close Aktif figürü kapat Save Aktif figürü kaydet Save As Aktif figürü farklı kaydet Export Aktif figürü m-file dosyası halinde kaydet Preferences Ayarlar sekmesini aç Print Yazdır

m-file Editörü

Durum editörü

Menü Editörü

Nesne Hizalama

Nesne Kutusu

Standart menü

Uygulama Çalıştıma Butonu

Figür Yüzeyi

Çalışma Penceresi

Boyutlandırma Kulakçığı

Nesne Listesi

Nesne Özellikleri

Piksel Cetveli

Page 6: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 6

Standart menüde Preferences botununa basıldığında aşağıda gösterilen özellikler penceresi açılmaktadır.Bu pencerede ‘’ Show names in component palette ‘’ sekmesinin seçili olmasını dikkat ediniz.Böylece nesneler geniş görüntüsü ile karşınıza çıkacaktır.

Edit Menü Standart düzenlemeler menüsüdür.Figür yüzeyinde bulunan nesnelerin düzenlenmesinde programcıya yardımcı olacaktır. View Menü Figür yüzeyi ve figür yüzeyinde bulunan nesnelerin özelliklerinin görüntülenmesinde kullanılmaktadır. Layout Menü Snap To Grid Bölümlenmiş alana oturtma Bring To Front Nesneyi en öne getirme Send To Back Nesneyi en arkaya gönderme Bring Forward Nesneyi bir adın öne getirme Send Backward Nesneyi bir adım arkaya gönderme

Page 7: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 7

Tools Menü Run Aktif figürü çalıştır Aling Objects Nesne hizalama Grid and Rulers Piksel cetveli ve bölmelendirme Menü Editor Menü editörü Tab Order Editor Durum editörü GUI options GUI ayarları Help Menü Yardım menüsüdür. GUI ÇALIŞMA PENCERESİ,FİGÜR YÜZEYİ VE BOYUTLANDIRMA KULAKÇIĞI GUI penceresi açtığınızda karşınıza gelen untitled1.fig adlı pencere çalışma penceresi olarak adlandırılır.Bu pencere nesne kutusu ve figür yüzeyi ve yardımcı parametreleri barındırır. Figür yüzeyi nesnelerin yerleştirileceği alanı belirlemektedir.Bu ızgaralı yüzey GUI programı tasarlandıktan sonra,program çalıştırıldığında karşımıza gelecek olan yüzeydir.Bu nedenle yüzey boyutlandırılması programcı için önemlidir.Nesnelerin karmaşasından kaçınılması görsellik yönünden düzenli bir yerleşim sağlanması için figür yüzeyi boyutlandırılabilir.Figür yüzeyini boyutlandırmak için boyutlandırma kulakçığının ileri veya geri sürüklenmesi ile figür yüzeyi istenilen boyuta getirilir. Figür yüzeyinin boyutu ayarlandıktan sonra nesnelerin piksel seviyesindeki yerleşimleri için gerekli olan ayarlamalar yapılmalıdır. TOOLs menüsünden Grid and Rulers sekmesi seçildiğinde aşağıdaki pencere açılır.

Show rulersFigür penceresinde piksel cetvellerinin görünürlüğünü sağlamaktadır. Grid Size Figür penceresinde nesnelerin birim sürüklenmesine karşılık gelen piksel değerini göstermektedir.Bu değer 20(yirmi) olarak seçilmesi nesnelerin boyutlandırılması ve sürüklenmesine uygun karşılığı vermektedir.

Page 8: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 8

Snap to GridFigür penceresinin ızgaralı halini göstermektedir. Bu kutucukların işaretli olmasına dikkat ediniz. GUI OBJE KUTUSU ( PROGRAMLANABİLİR NESNELER)

Obje Kutusunda bulunan nesneler yukarıdaki isimleri almaktadır.Bu nesneler programcının tasarımına göre figür penceresinde yer alır ve işlevleri yazılımda çalıştırılır. Değişik yazılım platformlarında farklı nesneler bulunabilir.Fakat yukarıda belirtilen standart nesneler yardımı ile tasarımlarınız rahatlıkla uygulanabilir haline gelir. Obje kutusunda olan nesneler sürükle bırak yöntemi ile figür yüzeyine aktarılır.

İmleç Seçme

Onay Butonu Kaydırma çubuğu

Tekli Seçim

Çoklu Seçim

Değiştirilebilir metin Sabit Metin

Açılımlı seçenek seçme

Liste Kutusu

İki Yönlü Onay

Grafik Çizdirme

Nesne Gruplandırma

Buton Gruplandırma

ActiveX Denetimleri

Page 9: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 9

GUI HİZALAMA DÜĞMESİ GUI hizalama penceresi yardımıyla figür yüzeyinde bulunan nesnelerin yatay ve düşey hizalamaları yapılabilir.Bunun için; Align Objects butonu yarmıyla veya Toolsalign objects yolu izlenerek Aling Objects Penceresine ulaşılır.

Bu pencere yardımı ile Figür yüzeyinde bulunan nesnelerin yatay(Vertical) ve düşey(Horizontal) hizalama ayarları yapılabilir.Bbelirtilen sekmeler altında hizalama(align) ve dağıtma(distribute) işlemleri gerçekleştirilir.

Page 10: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 10

MATLAB GUI MENÜ EDİTÖRÜ GUI Menü Editörü butonu ile Menü editörü aşağıda gösterilen Menü Editörü Penceresi açılmaktadır.

Matlab GUI Editörü programcının görsel tasarımı yapıp, programın işlevini kazandırtan sonra som kullanıcıya yardım sağlamak amaçlı oluşturulan programı kolaylaştırmaya yaramaktadır.Bu editör ile dosya,düzen,yazıcı çıktısı alma, sağ tuş menüleriyle tasarıma yardımcı işlevler katma yönünde çalıştırılır. *Bu konu uygulama örneklerinde ayrıntılı olarak işlenerek programlara katılacaktır. NESNE LİSTESİ VE NESNE ÖZELLİKLERİ BUTONLARI Nesne listesi butonu ile figür yüzeyinde bulunan nesnelerin listesi alınabilir. Nesne Özellikleri butonu ile seçili durumda bulunan nesnenin özellikleri görülebilir.

Uygulama Menüsü Sağ Tuş Menüsü

Seçenek adı

Secenek etiketi

Kısayol Tuş Secenekten önce ayraç çzgisi

Secenek seçili Görünümü

Secenek aktif

Secenek işlevi

Sağ Tuş menüsü

Alt menü seçeneği

Yeni standart menü

Secenek silme

Page 11: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 11

MATLAB UYGULAMA ÖZELLİKLERİ Matlab uygulama özelliklerine Tools menüsünden GUI Options seçeneğinden ulaşabilirsiniz.Bu yöntemle aşağıdaki pencere açılacaktır.

Bu pencerede yer alan Resize Behavior (Boyutlandırma) Non-resizableUygulama penceresi boyutu kullanıcı tarafından değiştirilemez. Proportional Uygulama penceresi boyutu kullanıcı tarafından orantılı olarak değiştirilebilir. Other (Use resizeFcn)Uygulama penceresi boyutu kullanıcı tarafından istenildiği şekilde değiştirilebilir. Command-line Accessibility (Komut Satırı Erişimi) On Komut satırından GUI figürüne etkileşim engellenir Off Komut satırından GUI figürüne etkileşim sağlanır. Other Nesne özellikleri penceresinden etkileşime izin verir. Bu pencerede diğer seçenekler kod yığınları ile ilgili seçeneklerdir.Bu seçenekler varsayılan şekilde kalması programcı için yarar sağlar.

Page 12: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 12

MATLAB GUI İLE TASARIM Öncelikli olarak şunu belirtmelim ki ; aşağıda anlatılan GUI nesnelerinin işlevlerinin nasıl kazandırılacağı anlatılmıştır. Nesnelerin programlanma aşamasında öğrenecekleriniz herhangi bir problemin çözümü veya herhangi bir tasarım değildir.Yani bir nesnenin işlevini binlerce farklı tasarımda kullanabilirsiniz. Özetle; bir tasarımda buton işlevi kullanılacksa farklı programı aynı işlev kullanarak kendi tasarımlarınızda kullanacaksınız.Böylece buton aynı işlevi yerine getirirken siz ya toplama işlemi yaptırırsınız yada çıkarma işlemi yaptırısınız.Yani her iki durumdada buton aynı işlevi görür. Şunu iyi bilmelisiniz GUI tasarımcısı olarak sadece tasarımı öğreniyorsunuz.Matlab ile programlama öğrenmediğinizi belirtmek isterim. Bana geri dönüşlere genelde problemin kendisi direk olarak gelmektedir.Bunun yerine bu dökümanı çalışmayı bitirdiğinizde ve örnekleri ayrıntılı olarak incelediğinizde aslında problemin çözümünü nesne bazında gerçekleştirebilecek seviyede tasarım biliyorsunuz demektir.Sadece size kalan tüm problemin çözümü için bu parametreleri bir araya getirip bütünleştirmektir.Böylece programınız ve GUI tasarımınız sorunsuzca çalışıyor olacaktır. Öncelikle size dökümanı çalışırken ve uygulamaları incelerken hangi konular üstünde duracağınızı belirtiyim.Matlab’ta onlarca kütüphane mevcuttur ve yüzlerce komut vardır.Tüm komutları bir tasarımcının bilmesi imkansızdır.Bunun için çalıştığınız alandaki komutları bilmeniz size programlama aşamasında yarar sağlayacaktır.Bu konuda Matlab yardım kütüphanesinden yardım alabilirsiniz. Nesneleri programlamayı gösterdikten sonra 1(bir) örnek uygulama yapmayı uygun gördüm.Böylece nesne işlevini öğrendikten sonra uygulama ile öğrendiklerinizi pekiştirebilirsiniz. Tüm Matlab GUI ile Tasarım anlatıldıktan sonra ayrıntılı uygulamalar ve bu uygulamaların tasarımları ayrıntılı olarak anlatılmış olup bu tasarımları incelemeniz, kendi tasarımlarınız için faydalı olacaktır.

Page 13: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 13

GİRİŞ; Tasarımda kullanacağımız en öncelikli komutlar ve işlevleri bir tablo halinde aşağıda verilmiştir. Komut,Değişken,Özellik Komut İşlevi (Açıklama) Gcbf Çalışılmakta olan gui figüründe Gcbo Çalışılmakta olan gui objesinde Persistent Sabit değer komutu Global Ortak değişken Save Dosya kaydetme Load Dosya yükleme isempty İlk değer Char Karaktere dönüştürme Str2num Sayıya dönüştürme Num2str Karaktere dönüştürme set Atama get Alma sprintf Karakter dizisi yaratma fprintf Ekran çıktısı alma findobj Nesneyi buldurma Tag Nesne etiketi value Nesne değeri string Nesne Adı Yukarıdaki komutlar tasarımda kullacağımız komutlardır.Bunların bilinmesi önemlidir.Ayrıca programla aşamasında kullanacağımız komutlar Matlab’ın programlama komutlarıdır.Tasarımını yapacağınız projenin programlama komutlarını bilmeniz gerekmektedir. NOT:ÖRNEK PROGRAMLARI İNCELERKEN, SİZİNDE AYNI PROGRAMLARI YAZMANIZ DURUMUNDA NESNE ETİKETLERİNE DİKKAT EDİNİZ.BURADA YAZILAN NESNE ETİKETLERİ İLE SİZİN NESNE ETİKETLERİNİZ BİRBİRİNİ KARŞILAMIYOR OLABİLİR PUSH BUTTON UYGULAMASI Push button; tasarımda bir işlevin yerine getirilmesi için fare ile tıklanması gereken yerlerde kulanılmalıdır. Tasarımımız push butona basıldığında ekrana ismimizi yazdıracağız. Nesne kutusundan fare ile bir adet push buttonu sürükle bırak yöntemi ile figür yüzeyine ekliyoruz.Aynı şekilde nesne kutusundan bir adet static text’i figür yüzeyine ekliyoruz. Figür yüzeyine eklediğiniz nesnelerin üzerine tıkladığınızda nesnelerin köşelerinde beliren siyah noktalar ile fare yardımıyla nesneleri istediğiniz boyutlara getirebilirsiniz. Bu işlemler sonrasında figür yüzeyinin son hali aşağıdaki şekilde görülmektedir.

Page 14: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 14

Bu aşamada nesne özelliklerindeki işlemleri gerçekleştirmeliyiz.Bunun için push button özelliklerine girip burada gerekli düzenlemeleri gerçekleştirmek gereklidir.Tüm nesnelerin ve figür penceresinin özellikler penceresi mevcuttur. Push buton üzerine çift tıklarsanız veya fare ile nesne üzerine sağ tıklayıp Property İnspector seceneğini seçerseniz, nesnenin özellikler penceresi açılacaktır.Aşağıda bu pencerenin görüntüsü verilmektedir.

Page 15: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 15

Tasarımcı olarak nesnelerin özelliklerine ulaşarak ve nesne için gerekli olan düzenlemeleri ve görsel temaları bu pencere yardımıyla düzenleyeceksiniz.Bu pencerede tasarımcı olarak bize yardımcı olacak birkaç özelliği burada anlatacağım. Backgroundcolor Nesnenin rengini belirlemede kullanılır. Callback Otomatik olarak atanacağından bu kısmı değiştirmiyoruz. Font özellikleri Font sekmeleri buton üzerindeki yazının biçemini belirler. Foregroundcolor Buton üzerindeki yazının rengini belirler. KeypressFcn Kısayol atama String Buton üzerindeki yazıdır. TAG Nesne etiketi.Bu özelliğin değiştirlmemesi önerilir. UIcontexmenu Sağ tuş menüsü. Visible Nesnenin açılışta görünür olup olmama durumudur. On-Görünürlük Off-Görünmezlik Yukarıda sıraladığım özellikler en geçerli özellikler olup tüm özellikler üzerinde değişiklik yapabilirsiniz. Push Butonun tasarımımıza gerekli olan özelliklerinden bazılarını değiştirelim. 1-Backgorundcolor sekmesindeki buton yardımıyla açılan renk penceresinden istediğiniz rengi belirleyiniz. Örnekte turuncu renk kullanılmıştır. 2-Foregroundcolor sekmesindeki buton yardımıyla açılan renk penceresinden istediğiniz rengi belirleyiniz.Örnekte mavi renk kullanılmıştır. Not1:Buton rengi ile yazı rengini aynı renk yapmamanız öenmlidir.Çünkü aynı renk olduklarında buton yazısı programda görülmeyecektir. 3-String kısmında yazan ‘pushbutton’ yazısını silerek yerine ‘isim yaz’ şeklinde yazıyoruz.Bu yazı bizim tasarımımıza uygun olacaktır. Not2:Matlab GUI tasarımı ve programlama aşamasında Türkçe karakter kullanılmamalıdır. 4-Static Text özellikler penceresinden string kısmını silip boş bırakıyoruz.Böylece tasarımımızın görseli sağlanmış olacaktır. 5-Static text özellikler penceresinde static text ekranın rengini belirliyoruz.Örnekte sarı olarak kullanılmıştır. Bu işlemlerden sonraki ekran görüntüsü aşağıda gösterilmiştir.

Page 16: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 16

Bu işlmelerin ardından tasarımımızı kaydedip programlama aşamasına geçiyoruz.Bunun için File menüsünden Save As seçeneğini secerek kaydetme penceresi açılacaktır.Bu pencerede figür ismini istediğiniz şekilde belirtebiliriz.Örnekte pushbutton olarak yazılmıştır. Tasarımımız Matlab’ın WORK klasörüne .fig uzantılı olarak pushbutton.fig olarak kaydedilmiş olacaktır. Bu kaydetme işlemi sonrasında Matlab pushbutton.m şeklinde otomatik olarak work klasöründe pushbutton.m adında m-function dosyası üretir.Editör penceresi bu pushbutton.m dosyasını otomatik olarak açar. Aşağıda work klasöründe kaydedilen dosyaları, pushbutton.fig ve pushbutton.m dosyasını görebilirsiniz.(Araçlar-klasör seçenekleri-görünüm-uzantıları gösterme onayını kaldırın) Böylece dosya uzantılarını görebilirsiniz

Page 17: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 17

Pushbutton.fig figür penceresi

Pushbutton.m adlı editör penceresi;

Page 18: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 18

Pushbutton.m adlı m-funtion dosyası tasarımımızı programlayacağımız dosyadır.İçeriği aşağıdaki şekildedir. function varargout = pushbutton(varargin) % PUSHBUTTON M-file for pushbutton.fig % PUSHBUTTON, by itself, creates a new PUSHBUTTON or raises the existing % singleton*. % % H = PUSHBUTTON returns the handle to a new PUSHBUTTON or the handle to % the existing singleton*. % % PUSHBUTTON('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PUSHBUTTON.M with the given input arguments. % % PUSHBUTTON('Property','Value',...) creates a new PUSHBUTTON or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before pushbutton_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to pushbutton_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help pushbutton % Last Modified by GUIDE v2.5 24-Aug-2012 20:12:41 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @pushbutton_OpeningFcn, ... 'gui_OutputFcn', @pushbutton_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before pushbutton is made visible.

Page 19: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 19

function pushbutton_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to pushbutton (see VARARGIN) % Choose default command line output for pushbutton handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes pushbutton wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = pushbutton_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) Yukarıda oluşan kodlar GUI’nın tasarımınız için oluşturduğu otomatik kodlardır. Nesnelerin işlevlerinin , tasarımda nasıl çalışacağının programlaması function pushbutton1_Callback(hObject, eventdata, handles) kısmında yazılmalıdır. Static text işlevsellik yönünden çıkış görüntüsü verdiğinden tasarımda programlamaya gerek yoktur.Sadece diğer nesnelerle birlikte kullanılır. Programlama şamasına geçelim.Açıklamalı uygulamalar için okuyanlar açısından anlaşılması kolay olsun diye % ile başlayan açıklama satırları ekledim.Bu satırları programlamada yazmanıza gerek yoktur.Normal uygulamalarda ise açıklama satırları eklenmemiştir. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','text1'); %çalışan figürde etiketi text1 olan nesneyi % %bul ve a ile tanımlanan değişkene ata set(a,'string','Harun YALÇIN');%a’nın string değerini Harun YALÇIN olarak % %ata

Nesne işlev

Page 20: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 20

Tasarımınız için yukarıdaki programı yazdığıktan sonra kaydedin.Böylece programınız Matlab GUI tarafından icra edilebilir duruma gelecektir. Run butonu ile programı çalıştırdığımızda ve ‘isim yaz’ butonuna basıldığındaki 2 farklı durumun ekran görüntüsü aşağıdaki gibi olacaktır.

Butona Basılmadan Önceki Durum

Butona basıldıktan sonraki Durum

Page 21: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 21

Bu işlemlerden sonra figür penceresi özelliklerimizi inceleyelim. Matlab GUI penceri üzerinde çift tıklama ve sağ tuş menüsünden fifür penceresinin Property Inspector penceresi açılacaktır.Bu özellik penceresinde GUI figür yüzeyi için özellikleri ayarlayabilisiniz.Aşağıda bu pencerenin ekran görüntüsü görebilirsiniz.

Bu özellikler penceresinde birkaç özellik denetimini anlatmaya çalışalım Color Figür yüzeyi rengini ayarlamaya yaramaktadır. Filename Figürün kaydedildiği dosyanın dosya yolunu göstermektedir. HandleVisibility Figür yüzeyinde çizimlerin gösterilmesine imkan sağlar. Menübar Tasarımınızda standart menünün eklenmesini sağlar(figüre secilmelidir) Name Tasarımınızda pencere ismini görüntülemektedir. Paper sekmeleri tasarımınızın kağıt düzlemi üzerindeki değişikleri ve düzenlemeleri yapılır. Windowstyle Tasarımınızın pencere stillerini ayarlayabilirsiniz.

Page 22: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 22

Örnek Uygulama: Butonlar yardımıyla 3 farklı rengi , 1 statix text kullanarak tanımlayınız. Programı tasarlama aşamasında 3 adet buton kullanacağız.3 farklı renk olarak ana renkler Kırmızı,sarı ve mavi’yi kullanacağız.Butonlara bastığımızda statik text’in rengini değiştireceğiz.

şeklinde GUI tasarımımızı yapıyoruz. Bu işlemlerden sonra butonların ve static text’lerin özellikler penceresinden gerekli ayarlamaları yaparak aşağıdaki ekran görüntüsü şekilde tasarımımızı yapıp, renkler.fig olarak kaydediyoruz. Program çalıştırıldığında ekran görüntüsü aşağıdaki gibidir.

Page 23: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 23

Program çalıştırılıp Kırmızı,mavi veya sarı renkli butonların herhangi birine basıldığında ise aşağıdaki ekran görüntüsü alınır.

Püf noktası olarak renk kodlarına özellikler penceresindeki red,green ve blue sekmelerinde karşılık gelen kodları görebilirsiniz. Programın m-function dosyası aşağıdadır.Program kodları kırmızı ile gösterilmiştir. function varargout = renkler(varargin) % RENKLER M-file for renkler.fig % RENKLER, by itself, creates a new RENKLER or raises the existing % singleton*. % % H = RENKLER returns the handle to a new RENKLER or the handle to % the existing singleton*. % % RENKLER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in RENKLER.M with the given input arguments. % % RENKLER('Property','Value',...) creates a new RENKLER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before renkler_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to renkler_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc.

Page 24: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 24

% Edit the above text to modify the response to help renkler % Last Modified by GUIDE v2.5 24-Aug-2012 22:19:28 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @renkler_OpeningFcn, ... 'gui_OutputFcn', @renkler_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before renkler is made visible. function renkler_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to renkler (see VARARGIN) % Choose default command line output for renkler handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes renkler wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = renkler_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Page 25: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 25

a=findobj(gcbf,'TAG','text1'); set(a,'backgroundcolor',[1.0 0 0]); b=findobj(gcbf,'TAG','text1'); set(b,'string','KIRMIZI'); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','text1'); set(a,'backgroundcolor',[0 0 1]); b=findobj(gcbf,'TAG','text1'); set(b,'string','MAVI'); % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','text1'); set(a,'backgroundcolor',[1 1 0]); b=findobj(gcbf,'TAG','text1'); set(b,'string','SARI');

Page 26: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 26

TOOGLE BUTON UYGULAMASI Toogle buton 2 farklı durumu kontrol etmek için kullanılır.Toogle buton Basılı olmadığı durumda ‘0’ , Basılı olduğu durumda ise ‘1’ değerini almaktadır. Program çalıştırıldığında toogle butonun değeri ‘0’ dır.Fakat bu değer için başlangıçta herhangi bir değer atanmadığından dolayı herhangi bir sonuç göstermeyecektir.Bu göz önüne alındığında programı yazma aşamasında başlangıçta toogle buton’un ‘0’ değerine başlangıç durumu için sonuç atamak uygun olacaktır. Tasarımımız toogle butonun durumunu gösterir bir uygulama yapacağız. Matlab Gui tasarım ekranında bir Toogle Butonu ve static text nesnesini figür yüzeyine sürükleyiniz. Toogle Buton özellikler penceresinden string kısmını silerek yenine ‘ DURUM ’ yazın.Toogle Butonun backgroundcolor sekmesinden rengini sarı olarak seçin. Statick text rengini yeşil olarak ayarlayın. Burada static textin başlangıç durumunu toogle butonun başlangıç durumuna göre ayarlamamız gerekmektedir.Toogle butonun başlangıç durumu ‘basılı değil konumu’ yani ‘0’ konumudur.Bu nedenle static text’in başlangıç durumuna ‘BASILI DEGIL ( 0 )’ şeklinde belirlemek gerekmektedir.Static text’in string kısmına BASILI DEGIL ( 0 ) yazarak bu başlangıç durumunu atarız. Böylece son ekran görüntüsü aşağıdaki gibi olacaktır.

Page 27: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 27

Bu programı tooglebutton.fig şeklinde kaydediyoruz.GUI ‘nin oluşturduğu tooglebutton.m dosyası oluşacaktır.Bu m-function dosyasında aşağıdaki kodlamayı yapacağız. global durum;%durum isimli glabol değişken oluştur. durum=get(gcbo,'value');%tooglebuttonun value değerini durum değişkenine ata a=findobj(gcbf,'TAG','text1');%etiketi text1 olan nesneyi a değişkenine ata if durum==0 %Eger durum değişkeninin değeri 0 ise set(a,'string','BASILI DEGIL (0)'); %static texte BASILI DEĞİL(0)yaz else %Eğer durum değişkeni değeri 0 değilse (Deger 1 olacaktır) set(a,'string','BASILI DURUMDA (1)');%static texte BASILI DURUMDA(1) yaz end Şeklinde programlamayı yapıp, tasarımızı çalıştırdığımızda;2 durumdada tasarımımızın görüntüleri aşağıdaki şekilde olacaktır.

Page 28: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 28

Yaptığımız tasarımın m-function dosyası aşağıdaki gibidir. function varargout = tooglebutton(varargin) % TOOGLEBUTTON M-file for tooglebutton.fig % TOOGLEBUTTON, by itself, creates a new TOOGLEBUTTON or raises the existing % singleton*. % % H = TOOGLEBUTTON returns the handle to a new TOOGLEBUTTON or the handle to % the existing singleton*. % % TOOGLEBUTTON('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TOOGLEBUTTON.M with the given input arguments. % % TOOGLEBUTTON('Property','Value',...) creates a new TOOGLEBUTTON or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before tooglebutton_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to tooglebutton_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help tooglebutton % Last Modified by GUIDE v2.5 26-Aug-2012 22:00:16 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @tooglebutton_OpeningFcn, ... 'gui_OutputFcn', @tooglebutton_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

Page 29: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 29

% --- Executes just before tooglebutton is made visible. function tooglebutton_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to tooglebutton (see VARARGIN) % Choose default command line output for tooglebutton handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes tooglebutton wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = tooglebutton_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in togglebutton1. function togglebutton1_Callback(hObject, eventdata, handles) % hObject handle to togglebutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of togglebutton1 global durum;%durum isimli glabol değişken oluştur. durum=get(gcbo,'value');%tooglebuttonun value değerini durum değişkenine ata a=findobj(gcbf,'TAG','text1');%etiketi text1 olan nesneyi a değişkenine ata if durum==0 %Eger durum değişkeninin değeri 0 ise set(a,'string','BASILI DEGIL (0)');%static texte BASILI DEĞİL(0)yaz else %Eğer durum değişkeni değeri 0 değilse (Deger 1 olacaktır) set(a,'string','BASILI DURUMDA (1)');%static texte BASILI DURUMDA(1) yaz end

Page 30: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 30

ÖRNEK UYGULAMA: Tasarım olarak toogle botonla tasarımımızda kullanacağımız başka bir nesnenin görünebilir özelliğine erişeceğiz.Böylece toogle butona bastığımızda nesne görünmez, toogle buton basılı değilken nesne görünür durumda olacaktır. Bunun için figür penceresine bir tooglebutton ile bir static text’i ekliyoruz. Toogle butonun özellikler penceresinden;renk olarak sarı olarak ayarlayıp string kımına ‘GİZLE’ yazıyoruz. Statick text’i figür yüzeyinde siz kullanıcıların görmesi için rengini turuncu olarak ayarlayıp,static text’in string kısmını silerek boş bırakıyoruz. Tasarımımızı gizli.fig olarak kaydediyoruz. Bu durumdaki ekran görüntüsü aşağıdaki gibi olacaktır.

Program çalıştırıldığında toogle butona basılmadan önceki görüntü aşağıdaki gibidir.

Page 31: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 31

Toogle butona basıldıktan sonraki durum ise aşağıdaki şekildedir.

Programın m-function dosyası aşağıdaki gibidir. function varargout = gizle(varargin) % GIZLE M-file for gizle.fig % GIZLE, by itself, creates a new GIZLE or raises the existing % singleton*. % % H = GIZLE returns the handle to a new GIZLE or the handle to % the existing singleton*. % % GIZLE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GIZLE.M with the given input arguments. % % GIZLE('Property','Value',...) creates a new GIZLE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gizle_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gizle_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help gizle % Last Modified by GUIDE v2.5 26-Aug-2012 22:44:59 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gizle_OpeningFcn, ... 'gui_OutputFcn', @gizle_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1})

Page 32: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 32

gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before gizle is made visible. function gizle_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to gizle (see VARARGIN) % Choose default command line output for gizle handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes gizle wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = gizle_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in togglebutton1. function togglebutton1_Callback(hObject, eventdata, handles) % hObject handle to togglebutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of togglebutton1 global durum; durum=get(gcbo,'value'); a=findobj(gcbf,'TAG','text1'); if durum==0 set(a,'visible','on'); else set(a,'visible','off'); end

Page 33: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 33

RADİO BUTTON UYGULAMASI Radio button tasarımı, genel kabul görmüş kullanımı birkaç seçenek içerisinden sadece 1(bir) adedini seçmek amacıyla kullanılır.Radio button seçildiğinde 1, seçili durumda değilken ise 0 değerini alır. Radiobutton birçok secenek içersinden değişik secenekleri seçmek içinde kullanılabilir.Fakat genel kullanımı tek seçeği secmek içindir.Bu nedenle herhangi bir seçeneği sectiğinizde diğer radio button seceneklerini seçilmemiş duruma getirmeniz gerekir.Bunu aşağıdak örnekte görebileceksiniz. Basit bir uygulama gerçekleştirmek için, öğrenim durumumuzu soran bir ve cevabımızı ekranda belirten bir tasarım geliştireceğiz. Figür penceremize 2 adet static text ve 3 adet radio button u yerleştiriyoruz. Birinci static text’in stringine Öğrenim durumu yazıyoruz.İkinci static text’in string kısmını silip boş bırakın. Radio button1 in özellikler penceresinden string kısmını silerek İLKOKUL yazın Radio button2 nin özellikler penceresinden string kısmını silip LİSE yazın Radio button3 ün özellikler penceresinden string kısmını silip ÜNİVERSİTE yazın Tasarımınızı Radiobutton.fig olarak kaydedin.Bu durumdaki tasarımımızın ekran görüntüsü aşağıdaki gibi olacaktır.

Şeklinde olacaktır.

Page 34: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 34

Radiobutton.m dosyasını aşağıdaki şekilde programlıyoruz. function varargout = radiobutton(varargin) % RADIOBUTTON M-file for radiobutton.fig % RADIOBUTTON, by itself, creates a new RADIOBUTTON or raises the existing % singleton*. % % H = RADIOBUTTON returns the handle to a new RADIOBUTTON or the handle to % the existing singleton*. % % RADIOBUTTON('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in RADIOBUTTON.M with the given input arguments. % % RADIOBUTTON('Property','Value',...) creates a new RADIOBUTTON or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before radiobutton_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to radiobutton_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help radiobutton % Last Modified by GUIDE v2.5 27-Aug-2012 20:50:35 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @radiobutton_OpeningFcn, ... 'gui_OutputFcn', @radiobutton_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before radiobutton is made visible.

Page 35: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 35

function radiobutton_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to radiobutton (see VARARGIN) % Choose default command line output for radiobutton handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes radiobutton wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = radiobutton_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton1 durum=get(gcbo,'value');%radiobutton değerini durum'a ata r2=findobj(gcbf,'TAG','radiobutton2');%etiketi radiobutton2 olan nesneyi 2'ye ata. r3=findobj(gcbf,'TAG','radiobutton3');%etiketi radiobutton3 olan nesneyi r3'ye ata. t2=findobj(gcbf,'TAG','text2');%etiketi text2 olan nesneyi t2'ye ata. if durum==1 %eğer radiobutton1 değeri 1 ise(seçili durumda) set(r2,'value',0);%r2 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(r3,'value',0);%r3 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(t2,'string','İLKOKUL');%t2 nesnesinin stringini İLKOKUL yap(ekrana İLKOKUL yaz) end % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Page 36: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 36

% Hint: get(hObject,'Value') returns toggle state of radiobutton2 durum=get(gcbo,'value');%radiobutton değerini duruma ata r1=findobj(gcbf,'TAG','radiobutton1');%etiketi radiobutton1 olan nesneyi r1'ye ata. r3=findobj(gcbf,'TAG','radiobutton3');%etiketi radiobutton3 olan nesneyi r3'ye ata. t2=findobj(gcbf,'TAG','text2');%etiketi text2 olan nesneyi t2'ye ata. if durum==1 %eğer radiobutton2 değeri 1 ise(seçili durumda) set(r1,'value',0);%r1 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(r3,'value',0);%r3 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(t2,'string','LİSE');%t2 nesnesinin stringini İLKOKUL yap(ekrana LİSE yaz) end % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton3 durum=get(gcbo,'value');%radiobutton değerini durum'a ata r1=findobj(gcbf,'TAG','radiobutton1');%etiketi radiobutton1 olan nesneyi r1'ye ata. r2=findobj(gcbf,'TAG','radiobutton2');%etiketi radiobutton2 olan nesneyi r2'ye ata. t2=findobj(gcbf,'TAG','text2');%etiketi text2 olan nesneyi t2'ye ata. if durum==1 %eğer radiobutton3 değeri 1 ise(seçili durumda) set(r1,'value',0);%r1 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(r2,'value',0);%r2 nesnesinin value değerini 0 yap(seçilmemiş duruma getir) set(t2,'string','ÜNİVERSİTE');%t2 nesnesinin stringini İLKOKUL yap(ekrana ÜNİVERSİTE yaz) end Programı çalıştırdığınızda ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 37: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 37

ÖRNEK UYGULAMA: Tasarımımız seçimize göre 4 farklı toolbox’a ulaşmak.Yani hangi toolbox’usecersek aynı toolbox klasörünün açılmasını sağlamak.Bunu programlar şeklinde veya binlerce farklı şekilde tasarımlarınızda kullanabilirsiniz. Tasarımımıza 1 adet pushbutton ve 4 farklı radio button ekleyip aşağıda görülen şekilde özelliklerini ayarlayın.

Page 38: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 38

Programı aşağıdaki gibi yazıyoruz. function varargout = toolboxac(varargin) % TOOLBOXAC M-file for toolboxac.fig % TOOLBOXAC, by itself, creates a new TOOLBOXAC or raises the existing % singleton*. % % H = TOOLBOXAC returns the handle to a new TOOLBOXAC or the handle to % the existing singleton*. % % TOOLBOXAC('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TOOLBOXAC.M with the given input arguments. % % TOOLBOXAC('Property','Value',...) creates a new TOOLBOXAC or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before toolboxac_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to toolboxac_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help toolboxac % Last Modified by GUIDE v2.5 27-Aug-2012 21:51:01 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @toolboxac_OpeningFcn, ... 'gui_OutputFcn', @toolboxac_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before toolboxac is made visible. function toolboxac_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB

Page 39: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 39

% handles structure with handles and user data (see GUIDATA) % varargin command line arguments to toolboxac (see VARARGIN) % Choose default command line output for toolboxac handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes toolboxac wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = toolboxac_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global r1; global r2; global r3; global r4; global dur1; global dur2; global dur3; global dur4; % --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton1 % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton2 % --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton3

Page 40: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 40

% --- Executes on button press in radiobutton4. function radiobutton4_Callback(hObject, eventdata, handles) % hObject handle to radiobutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton4 % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) r1=findobj(gcbf,'TAG','radiobutton1'); dur1=get(r1,'value'); r2=findobj(gcbf,'TAG','radiobutton2'); dur2=get(r2,'value'); r3=findobj(gcbf,'TAG','radiobutton3'); dur3=get(r3,'value'); r4=findobj(gcbf,'TAG','radiobutton4'); dur4=get(r4,'value'); if dur1==1 set(r2,'value',0); set(r3,'value',0); set(r4,'value',0); elseif dur2==1 set(r1,'value',0); set(r3,'value',0); set(r4,'value',0); elseif dur3==1 set(r1,'value',0); set(r2,'value',0); set(r4,'value',0); elseif dur4==1 set(r1,'value',0); set(r2,'value',0); set(r3,'value',0); end if dur1==1 winopen('C:\MATLAB701\toolbox\control\control');%ilgili klasörü aç elseif dur2==1 winopen('C:\MATLAB701\toolbox\fuzzy');%ilgili klasörü aç elseif dur3==1

Page 41: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 41

winopen('C:\MATLAB701\toolbox\images');%ilgili klasörü aç elseif dur4==1 winopen('C:\MATLAB701\toolbox\simulink');%ilgili klasörü aç end set(r1,'value',0); set(r2,'value',0); set(r3,'value',0); set(r4,'value',0); Program çalıştırılıp herhangi bir secenek seçilip AÇ butonuna bastığımızda aşağıdaki gibi bir ekran görüntüsü elde edilir.

Not:Programda herhangi bir başlangıç ataması yapmadığımız ve şu anda uyarı penceresi oluşturmayı anlatmadığımdan dolayı herhangi bir seçenek seçilmeden AÇ butonuna tıklarsanız herhangi bir işlem gerçekleşmez ve uyarı pencereside görüntülenmez. CHECKBOX UYGULAMASI Checkboz’ların çalışma mantığı da radiobutton’un çalışma mantığının aynısıdır.Fakat Checkbox’larda genel kullanım gereği seçeneklerden birden çok seçeneği seçme kullanımı yapılmaktadır.Checkbox seçili olduğu durumd 1, seçili olmadığı durumda 0 değerini almaktadır. Tasarım olarak bildiğimiz bilgisayar programlarını işaretleyerek ekrana yazdıralım. Bunun için 2 adet static text ve kısa olması için 3 adet checkbox’ı figür yüzeyimize yerleştiriyoruz. Birinci checkbox’ın rengini beyaz seçip stringine Microsoft Office yazıyoruz. İkinci checkbox’ın rengini beyaz seçip stringine AutoCad yazıyoruz. Üçüncü checkbox’ın rengini beyaz seçip stringine Matlab yazıyoruz.

Page 42: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 42

Birinci Static text in rengini beyaz seçip stringine Bildiğiniz Bilgisayar Programları yazıyoruz İkinci static text’in rengini beyaz seçip stringini boş bırakıyoruz. Programı bilgisayar.fig olarak kaydedin. Böylece aşağıdaki ekran görüntüsünü elde etmiş bulunuyoruz.

Açılan bilgisayar.m adlı dosyayı aşağıdaki şekilde programlıyoruz. function varargout = bilgisayar(varargin) % BILGISAYAR M-file for bilgisayar.fig % BILGISAYAR, by itself, creates a new BILGISAYAR or raises the existing % singleton*. % % H = BILGISAYAR returns the handle to a new BILGISAYAR or the handle to % the existing singleton*. % % BILGISAYAR('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in BILGISAYAR.M with the given input arguments. % % BILGISAYAR('Property','Value',...) creates a new BILGISAYAR or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before bilgisayar_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to bilgisayar_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES

Page 43: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 43

% Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help bilgisayar % Last Modified by GUIDE v2.5 28-Aug-2012 22:28:16 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @bilgisayar_OpeningFcn, ... 'gui_OutputFcn', @bilgisayar_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before bilgisayar is made visible. function bilgisayar_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to bilgisayar (see VARARGIN) % Choose default command line output for bilgisayar handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes bilgisayar wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = bilgisayar_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global dur1; global dur2; global dur3; global c1; global c2;

Page 44: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 44

global c3; global t2; % --- Executes on button press in checkbox1. function checkbox1_Callback(hObject, eventdata, handles) % hObject handle to checkbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox1 c1=findobj(gcbf,'TAG','checkbox1');%Checkbox1 nesnesini c1'e ata c2=findobj(gcbf,'TAG','checkbox2');%Checkbox1 nesnesini c2'e ata c3=findobj(gcbf,'TAG','checkbox3');%Checkbox1 nesnesini c3'e ata t2=findobj(gcbf,'TAG','text2');%Text2 nesnesini t2'e ata dur1=get(c1,'value');%Checkbox1 nesnesinin değerini dur1'e ata dur2=get(c2,'value');%Checkbox2 nesnesinin değerini dur2'e ata dur3=get(c3,'value');%Checkbox3 nesnesinin değerini dur3'e ata if dur1==1&dur2==0&dur3==0%eger sadece 1.si secili ise set(t2,'string','Microsoft Office');%ekrana yaz elseif dur1==1&dur2==1&dur3==0%eger sadece 1.si ve 2.si secili ise set(t2,'string','Microsoft Office,AutoCad')%ekrana yaz elseif dur1==1&dur2==1&dur3==1%eger 1.si,2.si ve 3.sü secili ise set(t2,'string','Microsoft Office,AutoCad,Matlab')%ekrana yaz elseif dur1==0&dur2==1&dur3==0%eger sadece 2.si secili ise set(t2,'string','Autocad');%ekrana yaz elseif dur1==1&dur2==1&dur3==0%eger sadece 1.si ve 2.si secili ise set(t2,'string','Microsoft Office,Autocad');%ekrana yaz elseif dur1==1&dur2==1&dur3==1%eger 1.si, 2.si ve 3.sü secili ise set(t2,'string','Microsoft Office,Autocad,Matlab');%ekrana yaz elseif dur1==0&dur2==0&dur3==1%eger sadece 3.sü secili ise set(t2,'string','Matlab');%ekrana yaz elseif dur1==1&dur2==0&dur3==1%eger sadece 1.si ve 3.sü secili ise set(t2,'string','Microsoft Office,Matlab');%ekrana yaz elseif dur1==1&dur2==1&dur3==1%eger 1.si ve 2.si ve 3.sü secili ise set(t2,'string','Microsoft Office,Autocad,Matlab');%ekrana yaz. end % --- Executes on button press in checkbox2. function checkbox2_Callback(hObject, eventdata, handles) % hObject handle to checkbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox2 c1=findobj(gcbf,'TAG','checkbox1'); c2=findobj(gcbf,'TAG','checkbox2'); c3=findobj(gcbf,'TAG','checkbox3'); t2=findobj(gcbf,'TAG','text2'); dur1=get(c1,'value'); dur2=get(c2,'value'); dur3=get(c3,'value'); if dur1==1&dur2==0&dur3==0 set(t2,'string','Microsoft Office'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,AutoCad') elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,AutoCad,Matlab') elseif dur1==0&dur2==1&dur3==0

Page 45: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 45

set(t2,'string','Autocad'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,Autocad'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); elseif dur1==0&dur2==0&dur3==1 set(t2,'string','Matlab'); elseif dur1==1&dur2==0&dur3==1 set(t2,'string','Microsoft Office,Matlab'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); end % --- Executes on button press in checkbox3. function checkbox3_Callback(hObject, eventdata, handles) % hObject handle to checkbox3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox3 c1=findobj(gcbf,'TAG','checkbox1'); c2=findobj(gcbf,'TAG','checkbox2'); c3=findobj(gcbf,'TAG','checkbox3'); t2=findobj(gcbf,'TAG','text2'); dur1=get(c1,'value'); dur2=get(c2,'value'); dur3=get(c3,'value'); if dur1==1&dur2==0&dur3==0 set(t2,'string','Microsoft Office'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,AutoCad') elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,AutoCad,Matlab') elseif dur1==0&dur2==1&dur3==0 set(t2,'string','Autocad'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,Autocad'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); elseif dur1==0&dur2==0&dur3==1 set(t2,'string','Matlab'); elseif dur1==1&dur2==0&dur3==1 set(t2,'string','Microsoft Office,Matlab'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); end Şeklinde programlanmalıdır.Program çalıştırılıp seceneklerden birkaç adet seçildiğinde aşağıdaki ekran görüntüsünü elde edersiniz.

Page 46: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 46

Not:Bir tasarımcı olarak programlarınızı en akılcı,en kısa ve en anlaşılır yoldan oluşturmanız gerekir.Böylece hem zamandan,hemde maliyetten kurtulursunuz. Bu nedenle yukarıdaki tasarımın aynısını farklı bir isimle bir buton ekleyerek aşağıda tekrar örnekledim.Böylece program yazımı aşamasındaki kısalığı ve daha anlaşılır durumu sizde göreceksiniz. 90’larda hayatımıza girip, şu an bile kullandığımız kopyala yapıştır mantığı dışında hareket etmiş olacağız.Çünkü yukarıdaki her bir checkbox’ı ayrı ayrı fakat aynı kodları yazdık. ÖRNEK UYGULAMA Bildiğimiz bilgisayar programlarını seçip bir buton yardımıyla ekrana yazdırmak istiyoruz. Figür penceremize 3 adet checkbox,2 adet static text ve 1 adet pushbutton ekleyipözellikler penceresinden aşağıda görülen şekilde ayarlamaları yapıyoruz.Daha sonra bilgisayarbuton.fig olarak kaydediyoruz.

Page 47: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 47

Programın bilgisayarbuton.m dosyası aşağıdaki gibidir. function varargout = bilgisayarbuton(varargin) % BILGISAYARBUTON M-file for bilgisayarbuton.fig % BILGISAYARBUTON, by itself, creates a new BILGISAYARBUTON or raises the existing % singleton*. % % H = BILGISAYARBUTON returns the handle to a new BILGISAYARBUTON or the handle to % the existing singleton*. % % BILGISAYARBUTON('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in BILGISAYARBUTON.M with the given input arguments. % % BILGISAYARBUTON('Property','Value',...) creates a new BILGISAYARBUTON or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before bilgisayarbuton_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to bilgisayarbuton_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help bilgisayarbuton % Last Modified by GUIDE v2.5 28-Aug-2012 23:11:10 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @bilgisayarbuton_OpeningFcn, ... 'gui_OutputFcn', @bilgisayarbuton_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

Page 48: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 48

% --- Executes just before bilgisayarbuton is made visible. function bilgisayarbuton_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to bilgisayarbuton (see VARARGIN) % Choose default command line output for bilgisayarbuton handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes bilgisayarbuton wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = bilgisayarbuton_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global dur1; global dur2; global dur3; global c1; global c2; global c3; global t2; % --- Executes on button press in checkbox1. function checkbox1_Callback(hObject, eventdata, handles) % hObject handle to checkbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox1 % --- Executes on button press in checkbox2. function checkbox2_Callback(hObject, eventdata, handles) % hObject handle to checkbox2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of checkbox2 % --- Executes on button press in checkbox3. function checkbox3_Callback(hObject, eventdata, handles) % hObject handle to checkbox3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Page 49: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 49

% Hint: get(hObject,'Value') returns toggle state of checkbox3 % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) c1=findobj(gcbf,'TAG','checkbox1'); c2=findobj(gcbf,'TAG','checkbox2'); c3=findobj(gcbf,'TAG','checkbox3'); t2=findobj(gcbf,'TAG','text2'); dur1=get(c1,'value'); dur2=get(c2,'value'); dur3=get(c3,'value'); if dur1==1&dur2==0&dur3==0 set(t2,'string','Microsoft Office'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,AutoCad') elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,AutoCad,Matlab') elseif dur1==0&dur2==1&dur3==0 set(t2,'string','Autocad'); elseif dur1==1&dur2==1&dur3==0 set(t2,'string','Microsoft Office,Autocad'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); elseif dur1==0&dur2==0&dur3==1 set(t2,'string','Matlab'); elseif dur1==1&dur2==0&dur3==1% set(t2,'string','Microsoft Office,Matlab'); elseif dur1==1&dur2==1&dur3==1 set(t2,'string','Microsoft Office,Autocad,Matlab'); end Böylece seçimleri yapıp butona baştığınızda aşağıdaki ekran görüntüsü alınır.

Böylece daha az kodla aynı amaca hizmet eden bir tasarım gerçekleştirmiş olursunuz.

Page 50: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 50

EDİT TEXT UYGULAMASI Edit text son kullanıcının tasarıma bilgi girişi sağlaması içindir.Bilgi girişi olarak karakter ve sayısal veriler kullanılır.Yalnız edit text’e yapılan girişler ve çıkışlar KARAKTER olarak algılanır.Bu nedenle edit text’e girdiğiniz sayısal verileri NUMERİK verilere çevirmeniz gerekmektedir.Aynı şekilde hesaplanan sayısal verileri yine NUMERİK verilere cevirerek edit text’te görüntülemeniz gerekmektedir.Eğer yukarıdaki ayarlara dikkat etmez iseniz giriş ve çıkış verilerinde hata görürsünüz. Edit text giriş ve çıkış verilerinde kullanmanız için 2 adet komut bulunmaktadır. Str2num( ) karakter verisini nümerik veriye çevir. Num2str( )Nümerik verisini sayısal veriye çevir. Bu 2 komut sayesinde edit tex’te girilen verileri programda kullanıp, program çıkış verilerinide görüntüleyebilirsiniz. Uygulamamız için gerekli olan 2 adet edit text’i figür penceremize ekliyoruz.2 adet static text’i çıkışları bir fonksiyonun çözümlenmesini görüntülemek için figür penceremize ekliyoruz. Ayrıca bir Pushbutton figür penceremize ekleyip buton sayesinde sonuçları görüntülecegiz. 2 adet edit text’in özellikler penceresinden stringlerini silip boş bırakın. 2 adet static text’in özellikler penceresinden stringlerini silip boş bırakın. Pushbutton’un özellikler penceresinden stringini silip Sonuçları Göster yazıyoruz. Renkleri istediğiniz şekilkde ayarlayabilirsiniz.Figür penceresini edittext.fig olarak kaydedin.Böylece tasarımımızın görüntüsü aşağıdaki şekilde olacaktır.

Page 51: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 51

Açılan edittext.m adlı programlama dosyası aşağıdaki gibidir. function varargout = edittext(varargin) % EDITTEXT M-file for edittext.fig % EDITTEXT, by itself, creates a new EDITTEXT or raises the existing % singleton*. % % H = EDITTEXT returns the handle to a new EDITTEXT or the handle to % the existing singleton*. % % EDITTEXT('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in EDITTEXT.M with the given input arguments. % % EDITTEXT('Property','Value',...) creates a new EDITTEXT or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before edittext_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to edittext_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help edittext % Last Modified by GUIDE v2.5 29-Aug-2012 21:48:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @edittext_OpeningFcn, ... 'gui_OutputFcn', @edittext_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT global giris1; global giris2; global cikis1; global cikis2; global karak1; global karak2; global karak3; global say;

Page 52: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 52

global sonuc; % --- Executes just before edittext is made visible. function edittext_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to edittext (see VARARGIN) % Choose default command line output for edittext handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes edittext wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = edittext_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) giris1=findobj(gcbf,'TAG','edit1');%1. edit text1 'i giriş1'e ata giris2=findobj(gcbf,'TAG','edit2');%2. edit text2 'i giriş2'e ata cikis1=findobj(gcbf,'TAG','text1');%1. static text1 'i cikis1'e ata cikis2=findobj(gcbf,'TAG','text2');%2. static text2 'i cikis2'e ata karak1=get(giris1,'string');%edit text1’e girilen karakter bilgiyi karak1’e ata set(cikis1,'string',karak1);%statictext1’e karakter bilgisini yaz karak2=get(giris2,'string'); %edit text1’e girilen karakter bilgiyi karak1’e ata say=str2num(karak2);%girilen karakter veriyi nümerik veriye cevir. sonuc=2*(say)+10;%nümerik veriyi işlemde yerine koy karak3=num2str(sonuc)%Nümerik veriyi karakter veriye dönüştür. set(cikis2,'string',karak3);%sonuç verisini static text2’ye yaz function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO)

Page 53: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 53

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end Not:Çıkış bilgileri static texte yazıldığından nümerik veriyi tekrar karaktere dönüştürmenize gerek olmamasına rağmen işlemin nasıl yapıldığını görmeniz açısından ekledim.

Page 54: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 54

ÖRNEK UYGULAMA: 4 kutuplu( 2 kutup çifti) sincap kafesli asenkron moturun frekans değerini klavye ile girerek senkron hızını hesapla 2 farklı değer için hesaplayınız. Bu tasarımda frekansı bir edittext ile gireceğiz.Sonuçları static text’ler yardımıyla görüntüleyeceğiz.Sonucu bulması için bir pushbutton kullanacağız. Tasarımımızı senkron_hiz.fig olarak kaydediceğiz. Figür tasarımının görüntüsü aşağıdaki şekildedir.

Programlanan senkron_hiz.m programı aşağıdaki şekildedir. function varargout = senkron_hiz(varargin) % SENKRON_HIZ M-file for senkron_hiz.fig % SENKRON_HIZ, by itself, creates a new SENKRON_HIZ or raises the existing % singleton*. % % H = SENKRON_HIZ returns the handle to a new SENKRON_HIZ or the handle to % the existing singleton*. % % SENKRON_HIZ('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SENKRON_HIZ.M with the given input arguments. % % SENKRON_HIZ('Property','Value',...) creates a new SENKRON_HIZ or raises the % existing singleton*. Starting from the left, property value pairs are

Page 55: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 55

% applied to the GUI before senkron_hiz_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to senkron_hiz_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help senkron_hiz % Last Modified by GUIDE v2.5 30-Aug-2012 12:18:52 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @senkron_hiz_OpeningFcn, ... 'gui_OutputFcn', @senkron_hiz_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before senkron_hiz is made visible. function senkron_hiz_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to senkron_hiz (see VARARGIN) % Choose default command line output for senkron_hiz handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes senkron_hiz wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = senkron_hiz_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure

Page 56: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 56

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) e1=findobj(gcbf,'TAG','edit1'); t1=findobj(gcbf,'TAG','text1'); fs=get(e1,'string'); fs=str2num(fs); ns=fs*120/(2*2); ns=num2str(ns); set(t1,'string',ns); Tasarımın ekran görüntüsü aşağıdaki şekilde olacaktır

Page 57: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 57

Page 58: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 58

SLİDER UYGULAMASI Slider’lar minimum 0 değeri alıp yükseklerek maksimum 1 değeri olan değişken veri giriş bandı olarak tanımlanabilir. Tasarım olarak bir nesnenin rengini slider kullanarak değişimlerini göstereceğiz. Bunun için 3 adet slider ve 1 adet static text kullanacağız.Fgür penceresine slider ve static text’i ekleyip,özellikler penceresinden static text’in stringini silip boş bırakıyoruz ve rengini beyaz olarak ayarlıyoruz. Sonra renk_tonu.fig olarak kaydedin.Bu şekilde aşağıdaki ekran görüntüsünü elde edeceksiniz.

Oluşan renk_tonu.m dosyası aşağıdaki şelikdedir. function varargout = renk_tonu(varargin) % RENK_TONU M-file for renk_tonu.fig % RENK_TONU, by itself, creates a new RENK_TONU or raises the existing % singleton*. % % H = RENK_TONU returns the handle to a new RENK_TONU or the handle to % the existing singleton*. % % RENK_TONU('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in RENK_TONU.M with the given input arguments. % % RENK_TONU('Property','Value',...) creates a new RENK_TONU or raises the % existing singleton*. Starting from the left, property value pairs are

Page 59: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 59

% applied to the GUI before renk_tonu_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to renk_tonu_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help renk_tonu % Last Modified by GUIDE v2.5 30-Aug-2012 12:52:23 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @renk_tonu_OpeningFcn, ... 'gui_OutputFcn', @renk_tonu_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before renk_tonu is made visible. function renk_tonu_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to renk_tonu (see VARARGIN) % Choose default command line output for renk_tonu handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes renk_tonu wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = renk_tonu_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB

Page 60: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 60

% handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global r1; global r2; global r3; global d1; global d2; global d3; global t1; % --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider d1=findobj(gcbf,'TAG','slider1');%slider1 nesnesini d1'e ata d2=findobj(gcbf,'TAG','slider2');%slider2 nesnesini d2'e ata d3=findobj(gcbf,'TAG','slider3');%slider3 nesnesini d3'e ata t1=findobj(gcbf,'TAG','text1');%text1 nesnesini t1'e ata r1=get(d1,'value');%d1 nesnesinin değerini r1'e ata r2=get(d2,'value');%d2 nesnesinin değerini r2'e ata r3=get(d3,'value');%d3 nesnesinin değerini r3'e ata set(t1,'backgroundcolor',[r1 r2 r3]);%text1'in renkgini sliderlerin değerlerine göre değiştir. % --- Executes during object creation, after setting all properties. function slider1_CreateFcn(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on slider movement. function slider2_Callback(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider d1=findobj(gcbf,'TAG','slider1');%slider1 nesnesini d1'e ata d2=findobj(gcbf,'TAG','slider2');%slider2 nesnesini d2'e ata d3=findobj(gcbf,'TAG','slider3');%slider3 nesnesini d3'e ata

Page 61: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 61

t1=findobj(gcbf,'TAG','text1');%text1 nesnesini t1'e ata r1=get(d1,'value');%d1 nesnesinin değerini r1'e ata r2=get(d2,'value');%d2 nesnesinin değerini r2'e ata r3=get(d3,'value');%d3 nesnesinin değerini r3'e ata set(t1,'backgroundcolor',[r1 r2 r3]);%text1'in renkgini sliderlerin değerlerine göre değiştir. % --- Executes during object creation, after setting all properties. function slider2_CreateFcn(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on slider movement. function slider3_Callback(hObject, eventdata, handles) % hObject handle to slider3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider d1=findobj(gcbf,'TAG','slider1');%slider1 nesnesini d1'e ata d2=findobj(gcbf,'TAG','slider2');%slider2 nesnesini d2'e ata d3=findobj(gcbf,'TAG','slider3');%slider3 nesnesini d3'e ata t1=findobj(gcbf,'TAG','text1');%text1 nesnesini t1'e ata r1=get(d1,'value');%d1 nesnesinin değerini r1'e ata r2=get(d2,'value');%d2 nesnesinin değerini r2'e ata r3=get(d3,'value');%d3 nesnesinin değerini r3'e ata set(t1,'backgroundcolor',[r1 r2 r3]);%text1'in renkgini sliderlerin değerlerine göre değiştir. % --- Executes during object creation, after setting all properties. function slider3_CreateFcn(hObject, eventdata, handles) % hObject handle to slider3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end Program çalıştırıp sliderların değerlerini değiştirdiğimizde ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 62: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 62

ÖRNEK UYGULAMA: Bilindiği üzere bir motora yol vermenin değişik metodları vardır.Bu metodlardan birisi frekans ayarlanarak yapılan yolvermedir.Ayrıca vektörel bazda gerilim ayarlaması yapılarak motor kalkerken yüksek demarak akımları kontrol edilebilir. Buna göre bir motorun yol vermede U/f kontrolünü bir slider yardımıyla yaparak motorun Senkron hız kontrolünü yapacağız.Motor olarak 4 kutuplu sincap kafesli asenkron motoru seçiyoruz. Gerlim ve frekansı rampa fonksiyonu şeklinde uygulayacağız. Figür penceremizin görüntüsü aşağıdaki gibidir.

Page 63: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 63

Program çalıştırıldığında ve slider ile değerini değiştirirseniz çıkışlarda elde edeceğiniz sonuçlar görüntülenecektir.Ayrıca motorların kayma hızları hesaplanmamıştır. function varargout = yolver(varargin) % YOLVER M-file for yolver.fig % YOLVER, by itself, creates a new YOLVER or raises the existing % singleton*. % % H = YOLVER returns the handle to a new YOLVER or the handle to % the existing singleton*. % % YOLVER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in YOLVER.M with the given input arguments. % % YOLVER('Property','Value',...) creates a new YOLVER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before yolver_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to yolver_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help yolver % Last Modified by GUIDE v2.5 30-Aug-2012 21:20:35 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @yolver_OpeningFcn, ... 'gui_OutputFcn', @yolver_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT global a; global b; global c; global s; global u; global f; global n; % --- Executes just before yolver is made visible. function yolver_OpeningFcn(hObject, eventdata, handles, varargin)

Page 64: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 64

% This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to yolver (see VARARGIN) % Choose default command line output for yolver handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes yolver wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = yolver_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider s=findobj(gcbf,'TAG','slider1'); a=get(s,'value'); b=findobj(gcbf,'TAG','text1'); c=findobj(gcbf,'TAG','text2'); u=a*400 %400 V nominal gerilimdir. f=a*50 %50 hz şebeke frekansıdır. n=f*120/(2*2); set(b,'string',u); set(c,'string',n'); % --- Executes during object creation, after setting all properties. function slider1_CreateFcn(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end

Page 65: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 65

Program çlıştırıldığında ekran görüntüsü aşağıdaki şekildedir.

Page 66: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 66

LİSTBOX UYGULAMASI Listbox nesnesi birçok seçeneğin içinden, bir tanesini secerek, programa işlev kazandıran nesnedir. Buna göre tasarımımızı bir listbox’tan bir meslek secerek bunu ekrana yazdıran bir program yazacağız. Figür penceremize bir listbox nesnesi ekleyiniz.Burada listbox’a seçenek eklemek için string kısmındaki butona mause ile tıklayarak string penceresini açmanız gerekir.Bu pencreler aşağıdaki şekildedir.

String Butonu

String Penceresi

Page 67: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 67

Mühendis Aldığı değer 1 Doktor Aldığı değer 2 Polis Aldığı değer 3 Hemşire Aldığı değer 4 Öğrenci Aldığı değer 5 Bankacı Aldığı değer 6 Serbest Çalışan Aldığı değer 7 Seçeneklerini bu string penceresine giriyoruz. Burada hangi seçenek seçili ise listbox nesnesi karşısındaki değeri alır.Seçenekler arttırılır ise değerler artarak yükselir. Figür penceresine çıkışları görüntülemek için bir adet static text ekliyoruz.Özellikler penceresinden string kısmını silip boş bırakın Bir pushbutton ekleyip Stringini silip Seçileni Yaz şeklinde yazın. Bu figürü listbox.fig olarak kaydedin.Bu şekildeki figürün ekran görüntüsü aşağıdaki şekildedir.

Açılan listbox.m dosyası aşağıdaki şekilde programlanır.

Page 68: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 68

function varargout = listbox(varargin) % LISTBOX M-file for listbox.fig % LISTBOX, by itself, creates a new LISTBOX or raises the existing % singleton*. % % H = LISTBOX returns the handle to a new LISTBOX or the handle to % the existing singleton*. % % LISTBOX('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in LISTBOX.M with the given input arguments. % % LISTBOX('Property','Value',...) creates a new LISTBOX or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before listbox_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to listbox_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help listbox % Last Modified by GUIDE v2.5 31-Aug-2012 19:52:17 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @listbox_OpeningFcn, ... 'gui_OutputFcn', @listbox_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT global a; global b; global secim; % --- Executes just before listbox is made visible. function listbox_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to listbox (see VARARGIN)

Page 69: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 69

% Choose default command line output for listbox handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes listbox wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = listbox_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','listbox1');%Listbox1 nesnesini a ya ata b=findobj(gcbf,'TAG','text1');%statictext1 nesnesini b ye ata secim=get(a,'value');%Listbox1'in aldığı değeri seçime ata switch(secim) case 1 %Listbox'ın aldığı değer 1 ise

Page 70: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 70

set(b,'string','Mühendis');%ekrana static texte Mühendis yaz case 2 %Listbox'ın aldığı değer 2 ise set(b,'string','Doktor');%ekrana static texte Doktor yaz case 3 %Listbox'ın aldığı değer 3 ise set(b,'string','Polis');%ekrana static texte Polis yaz case 4 %Listbox'ın aldığı değer 4 ise set(b,'string','Hemşire');%ekrana static texte Hemşire yaz case 5 %Listbox'ın aldığı değer 5 ise set(b,'string','Öğrenci');%ekrana static texte Öğrenci yaz case 6 %Listbox'ın aldığı değer 6 ise set(b,'string','Bankacı');%ekrana static texte Bankacı yaz case 7 %Listbox'ın aldığı değer 7 ise set(b,'string','Serbest Çalışan');%ekrana static texte Serbest Çalışan yaz end Program çalıştırıldığında ekran görüntüsü aşağıdaki gibidir.

Page 71: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 71

ÖRNEK UYGULAMA Tasarımızı listbox tan seçilen bir elektrik moturunun karşılığında 400 V ta anma akını görüntüleyeceğiz. (Değerler; Moeller Mühendislik El Kitabı’nın 9.bölüm 78. sayfasından alıntıdır.) Ekran figür pencresi aşağıdaki şekildedir.

Program motoranma.m dosyası aşağıdaki şekildedir. function varargout = motoranma(varargin) % MOTORANMA M-file for motoranma.fig % MOTORANMA, by itself, creates a new MOTORANMA or raises the existing % singleton*. % % H = MOTORANMA returns the handle to a new MOTORANMA or the handle to % the existing singleton*. % % MOTORANMA('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MOTORANMA.M with the given input arguments. % % MOTORANMA('Property','Value',...) creates a new MOTORANMA or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before motoranma_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to motoranma_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)".

Page 72: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 72

% % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help motoranma % Last Modified by GUIDE v2.5 31-Aug-2012 22:30:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @motoranma_OpeningFcn, ... 'gui_OutputFcn', @motoranma_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before motoranma is made visible. function motoranma_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to motoranma (see VARARGIN) % Choose default command line output for motoranma handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes motoranma wait for user response (see UIRESUME) % uiwait(handles.figure1); global a; global b; global secim; % --- Outputs from this function are returned to the command line. function varargout = motoranma_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;

Page 73: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 73

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','listbox1'); b=findobj(gcbf,'TAG','text1'); secim=get(a,'value'); switch(secim) case 1 set(b,'string','68'); case 2 set(b,'string','81'); case 3 set(b,'string','99'); case 4 set(b,'string','134'); case 5 set(b,'string','161'); case 6 set(b,'string','196'); case 7 set(b,'string','231'); case 8 set(b,'string','279'); end % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

Page 74: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 74

Programın çalıştırıldığında ekran görüntüsü aşağıdaki şekildedir.

POPUMENU UYGULAMASI Popupmenü , listbox nesnesinin liste halindeki görünümünün açılır menü haline getirilmiş durumdur.Aynı şekilde çalışırlar ve birçok seçenekten birini seçmek için kullanılır. Tasarımımızı listbox taki örneği popupmenu’ye uyarlyarak tekrarlayalım. Figür penceremize 1 adet popupmenu ekleyerek özellikler penceresinden string pencresine geçerek Mühendis Aldığı değer 1 Doktor Aldığı değer 2 Polis Aldığı değer 3 Hemşire Aldığı değer 4 Öğrenci Aldığı değer 5 Bankacı Aldığı değer 6 Serbest Çalışan Aldığı değer 7 Şeklinde yazalım. Yine 1 adet static text’i figür penceresine ekleyerek string kısmını silin ve boş bırakın. 1 adet push button ekleyip stringini Seçileni Yaz şeklinde değiştirin. Bu tasarımı popupmenu.fig olarak kaydedin.ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 75: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 75

Programın popupmenu.m dosyası aşağıdaki şekilde programlanır. function varargout = popupmenu(varargin) % POPUPMENU M-file for popupmenu.fig % POPUPMENU, by itself, creates a new POPUPMENU or raises the existing % singleton*. % % H = POPUPMENU returns the handle to a new POPUPMENU or the handle to % the existing singleton*. % % POPUPMENU('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in POPUPMENU.M with the given input arguments. % % POPUPMENU('Property','Value',...) creates a new POPUPMENU or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before popupmenu_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to popupmenu_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc.

Page 76: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 76

% Edit the above text to modify the response to help popupmenu % Last Modified by GUIDE v2.5 31-Aug-2012 22:57:58 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @popupmenu_OpeningFcn, ... 'gui_OutputFcn', @popupmenu_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before popupmenu is made visible. function popupmenu_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to popupmenu (see VARARGIN) % Choose default command line output for popupmenu handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes popupmenu wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = popupmenu_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global a; global b; global secim; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB

Page 77: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 77

% handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','popupmenu1'); b=findobj(gcbf,'TAG','text1'); secim=get(a,'value'); switch(secim) case 1 %popupmenu'ın aldığı değer 1 ise set(b,'string','Mühendis');%ekrana static texte Mühendis yaz case 2 %popupmenu'ın aldığı değer 2 ise set(b,'string','Doktor');%ekrana static texte Doktor yaz case 3 %popupmenu'ın aldığı değer 3 ise set(b,'string','Polis');%ekrana static texte Polis yaz case 4 %popupmenu'ın aldığı değer 4 ise set(b,'string','Hemşire');%ekrana static texte Hemşire yaz case 5 %popupmenu'ın aldığı değer 5 ise set(b,'string','Öğrenci');%ekrana static texte Öğrenci yaz case 6 %popupmenu'ın aldığı değer 6 ise set(b,'string','Bankacı');%ekrana static texte Bankacı yaz case 7 %popupmenu'ın aldığı değer 7 ise set(b,'string','Serbest Çalışan');%ekrana static texte Serbest Çalışan yaz end % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end Ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 78: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 78

ÖRNEK UYGULAMA Bir AG veya YG Projelendirmesi yaptğınızı düşünelim.Yeraltı veya havai hat projelendirmesinde kullanılan kablo veya iletkenlerin akım taşıma kapasitelerine ihtiyacınız var.Böyle bir durumda popupmenuler yardımıyla bu akım taşıma kapasitelerine ulaşılacak bir tasarım yapalım.(Örnekte program yazılımınu uzatmamak için her seçenekten 3 adet kablo veya iletken alınmıştır.İnternet üzerinde bu değerlere tablolar halinde ulaşılabilir.) Not:Akım taşıma kapasiteleri Elektrik Mühendisleri Odasının Elektrik Tesisat Projelerinin Hazırlanması ve Kontrolünde Dikkat Edilecek Hususlar Kitapçığının 23 ve 81. sayfalarından alınmıştır. Figür penceremizin görüntüsü aşağıdaki şekilde olacaktır.

Page 79: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 79

Programın kapasite.m isimli programlama dosyası aşağıdaki şekildedir. function varargout = kapasite(varargin) % KAPASITE M-file for kapasite.fig % KAPASITE, by itself, creates a new KAPASITE or raises the existing % singleton*. % % H = KAPASITE returns the handle to a new KAPASITE or the handle to % the existing singleton*. % % KAPASITE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in KAPASITE.M with the given input arguments. % % KAPASITE('Property','Value',...) creates a new KAPASITE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before kapasite_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to kapasite_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help kapasite % Last Modified by GUIDE v2.5 02-Sep-2012 19:49:28 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @kapasite_OpeningFcn, ... 'gui_OutputFcn', @kapasite_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before kapasite is made visible. function kapasite_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to kapasite (see VARARGIN)

Page 80: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 80

% Choose default command line output for kapasite handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes kapasite wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = kapasite_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global a; global b; global c; global d; global e; global f; global g; global sec1; global sec2; global sec3; global sec4; global sec5; global sec6; global yaz; % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) a=findobj(gcbf,'TAG','popupmenu1'); b=findobj(gcbf,'TAG','popupmenu2'); c=findobj(gcbf,'TAG','popupmenu3'); d=findobj(gcbf,'TAG','popupmenu4'); e=findobj(gcbf,'TAG','popupmenu5'); f=findobj(gcbf,'TAG','popupmenu6'); g=findobj(gcbf,'TAG','text1'); sec1=get(a,'value'); sec2=get(b,'value'); sec3=get(c,'value'); sec4=get(d,'value'); sec5=get(e,'value'); sec6=get(f,'value'); if sec1==1&&sec2==1 set(c,'visible','on') set(d,'visible','off') set(e,'visible','off') set(f,'visible','off')

Page 81: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 81

switch(sec3) case 1 set(g,'string','88'); case 2 set(g,'string','77'); case 3 set(g,'string','275'); end end if sec1==1&&sec2==2 set(d,'visible','on') set(e,'visible','off') set(f,'visible','off') set(c,'visible','off') switch(sec4) case 1 set(g,'string','203'); case 2 set(g,'string','246'); case 3 set(g,'string','293'); end end if sec1==2&&sec2==1 set(e,'visible','on') set(d,'visible','off') set(c,'visible','off') set(f,'visible','off') switch(sec5) case 1 set(g,'string','110'); case 2 set(g,'string','165'); case 3 set(g,'string','225'); end end if sec1==2&&sec2==2 set(f,'visible','on') set(c,'visible','off') set(e,'visible','off') set(d,'visible','off') switch(sec6) case 1 set(g,'string','110'); case 2 set(g,'string','193'); case 3 set(g,'string','225'); end end % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Page 82: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 82

% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu3. function popupmenu3_Callback(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu3 % --- Executes during object creation, after setting all properties.

Page 83: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 83

function popupmenu3_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu4. function popupmenu4_Callback(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu4 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu4 % --- Executes during object creation, after setting all properties. function popupmenu4_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu5. function popupmenu5_Callback(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu5 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu5 % --- Executes during object creation, after setting all properties. function popupmenu5_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called

Page 84: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 84

% Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu6. function popupmenu6_Callback(hObject, eventdata, handles) % hObject handle to popupmenu6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu6 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu6 % --- Executes during object creation, after setting all properties. function popupmenu6_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end Program çalıştırıldığında ekran görüntüsü aşağıdaki şekildedir.

Page 85: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 85

AXES UYGULAMASI Axes nesnesi, tasarımınız üzerinde bir çizim veya bir resim görüntülemek amacıyla kullanılır. Örnek bir tasarım gerçekleştirmek amacıyla figür penceresine 2 adet axes nesnesi yerleştiriniz. Bu Axes nesnelerinden birisi için sinüsoidal bir eğri, diğeri içinde resim göstermek için kullanacağız. 2 adet pushbutton’u figür penceresine yerleştiriniz.Bunlardan bir tanesinin stringini ÇİZ olarak, diğerinide GÖSTER olarak ayarlayın. Bu figürü grafik.fig olarak kaydedin Bu durumda Ekran görüntüsü aşağıdaki şekilde olacaktır.

Bu tasarımı çalıştırdığımızda aşağıdaki ekran görüntüsünü elde ederiz.

İlk axes ‘te u=10*cos(t) grafiğini çizdireceğiz. 2.axes’te ise bir resim gösterilecektir.(Resim ekleme daha sonraki bölümlerde anlatılmıştır.)

Page 86: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 86

Programın grafik.m dosyası ve çalıştırılıp butonlara basınca ekran görüntüsü aşağıdaki şekildedir. Programlama dosyasında axes(handles.axes1) ve axes(handles.axes2) çizimin hangi axes’te çizileceğini göstermektedir. function varargout = grafik(varargin) % GRAFIK M-file for grafik.fig % GRAFIK, by itself, creates a new GRAFIK or raises the existing % singleton*. % % H = GRAFIK returns the handle to a new GRAFIK or the handle to % the existing singleton*. % % GRAFIK('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GRAFIK.M with the given input arguments. % % GRAFIK('Property','Value',...) creates a new GRAFIK or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before grafik_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to grafik_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help grafik % Last Modified by GUIDE v2.5 03-Sep-2012 18:20:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @grafik_OpeningFcn, ... 'gui_OutputFcn', @grafik_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before grafik is made visible.

Page 87: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 87

function grafik_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to grafik (see VARARGIN) % Choose default command line output for grafik handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes grafik wait for user response (see UIRESUME) % uiwait(handles.figure1); global t; global u; global r; % --- Outputs from this function are returned to the command line. function varargout = grafik_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1) f=50; t=0:1:100; u=10*cos(t); plot(t,u) % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes2) a=imread('kedi.jpg'); image(a) NOT:AXES kullanımı yukarıdaki örnekle aynı olduğundan ayrıca bir örnek kullanmadım.

Page 88: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 88

ACTİVEX CONTROL UYGULAMASI Active X nesneleri; GUI tasarımlarında ,GUI figür yüzeyi nesnelerinin bağlılğından kurtararak, çok farklı nesneleri tasarımımıza ekleyerek programımıza işlev kazandırır. Figür penceresinde ActiveX nesnesine tıklayarak figür pencresinde mause yardımı ile bir kare çizin.Bu durumda aşağıdaki ActiveX penceresi açılacaktır.

Bu pencerede Control List bölümünden tasarımınıza eklemek istediğiniz bir nesne seçilebilir. Preview bölümünde bu nesnenin görüntüsü görülmektedir.Eklemek istediğiniz nesneyi sectikten sonra Create butonuna basarsanız gerekli nesne figür pencesine eklenecektir. Tasarımımız farklı günlere ait farklı resmler göstermek olacaktır.Bunun için figür penceresine yukarıda anlatılan şekilde 1 adet Takvim Denetimi , 1 adet Axes nesnesi ekleyiniz. 1 adet pushputton ekleyip rengini beyaz yapın stringini GÖSTER şeklinde yazın. Bu figür pencresini takvim.fig olarak kaydedin. Bu durumda Ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 89: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 89

Programın takvim.m adlı programlama dosyası aşağıdaki şekildedir. function varargout = takvim(varargin) % TAKVIM M-file for takvim.fig % TAKVIM, by itself, creates a new TAKVIM or raises the existing % singleton*. % % H = TAKVIM returns the handle to a new TAKVIM or the handle to % the existing singleton*. % % TAKVIM('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in TAKVIM.M with the given input arguments. % % TAKVIM('Property','Value',...) creates a new TAKVIM or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before takvim_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to takvim_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc.

Page 90: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 90

% Edit the above text to modify the response to help takvim % Last Modified by GUIDE v2.5 04-Sep-2012 20:50:47 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @takvim_OpeningFcn, ... 'gui_OutputFcn', @takvim_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before takvim is made visible. function takvim_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to takvim (see VARARGIN) % Choose default command line output for takvim handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes takvim wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = takvim_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global a; global b; global c; global d; global gun; % --- Executes on button press in pushbutton1.

Page 91: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 91

function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) gun=get(handles.activex1,'DAY');%takvim'in DAY (gün) değerini gun'e ata a=imread('DAU.jpg');%DAU.jpg isimli resmi import et ve a'ya ata b=imread('GUL.jpg');%GUL.jpg isimli resmi import et ve b'ya ata c=imread('KK.jpg');%KK.jpg isimli resmi import et ve c'ya ata d=imread('kedi.jpg');%kedi.jpg isimli resmi import et ve d'ya ata if gun==1 %Eğer gun=1 ise axes(handles.axes1) %axes1 'de image(a) %a resmini göster elseif gun==5 %Eğer gun=5 ise axes(handles.axes1)%axes1 'de image(b) %b resmini göster elseif gun==25 %Eğer gun=25 ise axes(handles.axes1)%axes1 'de image(c) %c resmini göster else %1,5,25 dışında bir sayı ise axes(handles.axes1)%axes1 'de image(d) %d resmini göster end Program çalıştırıldığında ve 5. gün seçildiğinde ekran görüntüsü aşağıdaki şekilde olacaktır.

ActiveX nesnelerinin programda nasıl bir işlev gördüğünü burada görmüş olduk.

Page 92: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 92

STATİC TEXT, PANEL ve BUTTON GROUP Static text nesnesi tasarımda çıkış verilerinin görüntülenmesinde veya tasarımda ekranda görülecek sabit verilerin yazıların yazılmasında kullanılır.Bunun içn özellikler penceresinden STRİNG özelliği kullanılır.Örnek uygulamalarda kullanılan statictextler size bu konuda yardımcı olur. Panel nesnesini bir kokpit olarak düşünebilirsiniz.Bir tasarımda değişik nesnelerin bir arada kullanıcıya sunulmasında görsellik kazandırır.Kullanıcının tasarımda kullanması gereken nesneleri bu çerçeve içerinde barındırabilirsiniz.Özellikler penceresinden TİTLE özelliğini kullanarak Panel yazısını istediğiniz şekilde değiştirebilirsiniz. Button Group nesnesi birden çok butonun gruplandırılması için kullanılan bir çerçevedir. Özellikler penceresinden TİTLE özelliğini kullanarakButton Group yazısını istediğiniz şekilde değiştirebilirsiniz. Bu 3 nesne için herhangi bir işlevsellik oluşturamazsınız.Bu nedenle *.m olan programlama dosyalarında callback’leri bulunmamaktadır. Ekran görüntüleri aşağıdaki şekildedir.

Page 93: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 93

MATLAB GUI ‘DE ETKİLEŞİM KUTULARI

İyi bir tasarımcı, tasarımının tüm giriş çıkış verilerini düşünmeli, yazılımının algoritmasını iyi bir iskelete oturtması gerekir.Her tasarımcının kendine özgü bir yazılımı vardır.Sadece kodlar aynıdır.Fakat iyi bir tasarımcı olmak için, tasarımınızı kullanan son kullanıcının programla ilgili tüm isteklerine cevap verecek seviyede, kısa ve anlaşılır bir yazılımla yapmasınız gerekir.Böylece uzun uzadıya kod yığınları dışında daha başarılı kısa yazılımlar oluşturursunuz.

Yazılımınızda tasarımcının yapacağı hatalar dışında kullanıcıdan kaynaklanan

hatalarda olabilir.Bu hataları en asgari düzeye indirmek ve kullanıcıyı bilgilendirmek için itkileşim pencereleri kullanılır.

Ayrıca kullanıcı tasarımınızı kullanırken kendi istekleri doğrultusunda programı işletebilmelidir.Bu tür istekleri tasarımınıza ekleyerek kullanıcının isteklerine yanıt sağlamış olursunuz.

Tüm bunları yapabilmeniz için etkileşim kutularından faydalanılır. Etkileşim kutuları MODAL ve NONMODAL şeklinde iki farklı durumda incelenir.

Modal etkileşim kutuları;kullanıcının programa dönebilmesi için etkileşim kutusundaki bazı işlevleri yerine getirmelidir. Nonmodal etkileşim kutuları;kullanıcı etkileşim kutusunda bir işlev yapmadan programa dönebilir. Etkileşim kutularını Modal veya Nonmodal yapmak tasarımcının elindedir.Bu nedenle yazılımınızı en etkin şekilde nasıl kullanıma sunacaksanız bu şekilde etkileşim kutularını kullanmanız önerilir. Programlama kullancağımız bazı etkileşim kutuları aşağıda liste halinde verilmiştir. Etkileşim Kutusu İsimleri Açıklamaları Errordlg Hata penceresi Helpdlg Yardım penceresi İnputdlg Veri giriş penceresi Questdlg Sorgu penceresi Warndlg Uyarı penceresi Msgbox Mesaj iletim kutusu Waitbar Yükleme çubuğu Listdlg Liste görünüm penceresi Printdlg Yazdırma penceresi Uigetfile Dosya açma penceresi Uiputfile Dosya kaydetme penceresi Uisetcolor Renk seçim pencresi uisetfont Karakter tipi penceresi Pagesetupdlg Sayfa yapısı penceresi printpreview Sayfa önizleme penceresi

Page 94: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 94

ERRORDLG Etkileşim Kutusu (Hata penceresi) Bir tasarımda program icra edilirken oluşabilecek hatalarda kullanıcı bilgilendirmek için kullanılır. Kullanılışı; errordlg(‘bilgilendirme mesajı’,’pencere başlığı’,’pencere özelliği’) şeklinde kullanılır. Hata penceresi için try catch end hata akımından yararlanılır.Programda bu pencereyi kullanmak için aşağıdaki şekilde programlama yazılmalıdır. try %Buraya %program kodları %yazılır. catch errordlg(‘bilgilendirme mesajı’,’pencere başlığı’,’pencere özelliği’) end şeklinde kullanılır. HELPDLG Etkileşim Kutusu ( Yardım Penceresi ) Bir tasarımda program icra edilirken kullanıcıyı tasarım ile ilgili yardım belirtilmesi için kullanılır Kullanılışı; helpdlg(‘bilgilendirme mesajı’,’pencere başlığı’) şeklinde kullanılır. WARNDLG Etkileşim Kutusu ( Uyarı Penceresi ) Bir tasarımda program icra edilirken kullanıcıyı uyarmak için kullanılır. Kullanılışı; warndlg(‘bilgilendirme mesajı’,’pencere başlığı’,’pencere özelliği’) şeklinde kullanılır. Bu 3 adet etkileşim kutusunun ekran görüntülerini aşağıdaki şekilde gösrebilirsiniz. Bunun için figür pencresine 3 adet pushbutton ekleyip; 1.sine Hata Penceresi 2.sine Yardım Penceresi 3.süne Uyarı Penceresi yazın.

Page 95: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 95

Programı pencere.fig olarak kaydedin.Bu durumda ekran görüntüsü aşağıdaki şekilde olacaktır.

Programın pencere.m dosyası aşağıdaki şekilde olacaktır. function varargout = pencere(varargin) % PENCERE M-file for pencere.fig % PENCERE, by itself, creates a new PENCERE or raises the existing % singleton*. % % H = PENCERE returns the handle to a new PENCERE or the handle to % the existing singleton*. % % PENCERE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PENCERE.M with the given input arguments. % % PENCERE('Property','Value',...) creates a new PENCERE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before pencere_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to pencere_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help pencere % Last Modified by GUIDE v2.5 05-Sep-2012 22:25:01

Page 96: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 96

% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @pencere_OpeningFcn, ... 'gui_OutputFcn', @pencere_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before pencere is made visible. function pencere_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to pencere (see VARARGIN) % Choose default command line output for pencere handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes pencere wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = pencere_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) errordlg('Program Esnasında Hata Olustu','HATA','modal') % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles)

Page 97: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 97

% hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) helpdlg('Sayısal veri Girmelisiniz','YARDIM') % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) warndlg('Sayısal Veri Girisi yapilmadi','UYARI','nonmodal') Program çalıştırılıp istenilen butona tıkladığınızda pencereleri aşağıdaki şekilde görebilirsiniz.

Diğer pencereler aşağıdaki şekildedir.

Page 98: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 98

MSGBOX( Mesaj Penceresi) Tasarımınızı kullanan son kullanıcıyı programın işleyişi sırasında herhangi bir nedenle veya tasarımınızla ilgili bir konu hakkında mesaj vermeniz için mesaj Penceresini kullanabilirsiniz. Mesaj Penceresinin Kullanılışı; msgbox(‘mesaj’) msgbox(‘mesaj’,’başlık’) msgbox(‘mesaj’,’başlık’,’ikon’) msgbox(‘mesaj’,’pencere başlığı’,’custom’,’resimdatası,resim renk haritası’) şeklinde kullanımları mevcuttur. İkon pencere de görüntülenecek olan resmi belirtir. Figür yüzeyine bir pushbutton ekleyerek stringini mesaj kutusu yazın.Figürü mesaj.fig olarak kaydedin.Programın mesaj.m yazılımı aşağıdaki şekilde olacaktır. function varargout = mesaj(varargin) % MESAJ M-file for mesaj.fig % MESAJ, by itself, creates a new MESAJ or raises the existing % singleton*. % % H = MESAJ returns the handle to a new MESAJ or the handle to % the existing singleton*. % % MESAJ('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in MESAJ.M with the given input arguments. % % MESAJ('Property','Value',...) creates a new MESAJ or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before mesaj_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to mesaj_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help mesaj % Last Modified by GUIDE v2.5 06-Sep-2012 21:13:58 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @mesaj_OpeningFcn, ... 'gui_OutputFcn', @mesaj_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1})

Page 99: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 99

gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before mesaj is made visible. function mesaj_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to mesaj (see VARARGIN) % Choose default command line output for mesaj handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes mesaj wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = mesaj_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) msgbox('Ornek Bir Uygulama Inceliyorsunuz.','Mesaj','help')

Page 100: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 100

Programı çalıştırdığınızda ekran görüntüsü aşağıdaki şekilde olacaktır.

INPUTDLG Etkileşim Kutusu ( Veri Giriş Penceresi) Tasarımınızı kullanan son kullanıcıdan, program işleyişi esnasında veri giriş bilgisi istediğinde kullanılır. Kullanılışı; Veri_Matrisi=inputdlg(Soru_Matrisi,’Pencere Başlığı’,satır_sayısı,’Başlangıç değerleri’) Şeklindedir. Bu pencerede sorular_matrisi bir adet satır matrisidir.Bu satır matrisi sorularınız kadar satır içerir. Sorular_matrisi={‘soru1’,’soru2’,………’soru_n’} şeklinde kullanılır. Satır sayısı,kullanıcıdan veri giriş penceresinde istenen girdi satır sayısını gösterir ( böylece verinin girildiği edittext ekran büyüklüğünü ayarlar. Başlangıç değerleri programda kullanmayı planladığınız ilk veri değerlerini gösterir. Veri_Matrisi, kullanıcnın girmiş olduğu değerlerin atandığı matristir. Konuyu daha iyi kavramanız açısından açıklamalı bir örnek yapalım. Son kullanıcıdan veri girişi olarak alacağımız bilgileri ekrana yazdıralım.

Page 101: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 101

Aşağıda girisler.fig programının girisler.m adlı dosyası mevcuttur. function varargout = Girisler(varargin) % GIRISLER M-file for Girisler.fig % GIRISLER, by itself, creates a new GIRISLER or raises the existing % singleton*. % % H = GIRISLER returns the handle to a new GIRISLER or the handle to % the existing singleton*. % % GIRISLER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GIRISLER.M with the given input arguments. % % GIRISLER('Property','Value',...) creates a new GIRISLER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before Girisler_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to Girisler_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help Girisler % Last Modified by GUIDE v2.5 08-Sep-2012 21:47:16 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @Girisler_OpeningFcn, ... 'gui_OutputFcn', @Girisler_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before Girisler is made visible. function Girisler_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to Girisler (see VARARGIN)

Page 102: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 102

% Choose default command line output for Girisler handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes Girisler wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = Girisler_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) t1=findobj(gcbf,'TAG','text1'); sorular={'ISIM','YAS','MESLEK'}; pencere_basligi='cevaplayiniz'; baslangic={'','',''}; alinan_veri=inputdlg(sorular,pencere_basligi,1,baslangic); set(t1,'string',alinan_veri); Programı çalıştırdığınızda ve ilgili girişleri sağladınızda ekran görüntüsü aşağıdaki şekilde olacaktır.

Page 103: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 103

Programda alinan_veri matrisi aşağıdaki şekilde atanır. Alinan_veri= ‘Harun YALÇIN’ ‘29’ ‘Elektrik Elektronik Mühendisi’ şeklindedir. QUESTDLG Etkileşim Kutusu(Sorgu Penceresi) Sorgu penceresi , programın işleyişi sırasında kullanıcıdan birkaç seçenekten birini seçmesinin istendiği durumlarda kullanılır. Kullanışı; Sorgu=(‘soru’,’pencere_baslığı’,’cevap1’,’cevap2’,’cevap3’,’varsayılan’) Şeklindedir. Soru , kullanıcıdan cevaplamasını istedeğiniz sorudur, Cevap1,cevap2 ve cevap3 kullanıdan seçmesini istediğini cevaplardır. Varsılan , cevaplar içinde varsayılan cevaptır.Bu cevap pencerede kalın puntoyla seçilmiş durumda yazılır. Örnekte 3 secenekten birini seçip ekrana yazdıran SORGU adlı bir program yazıyoruz. Sorgu.m dosyası aşağıdaki şekilde olacaktır. function varargout = sorgu(varargin) % SORGU M-file for sorgu.fig % SORGU, by itself, creates a new SORGU or raises the existing % singleton*. % % H = SORGU returns the handle to a new SORGU or the handle to % the existing singleton*. % % SORGU('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SORGU.M with the given input arguments. % % SORGU('Property','Value',...) creates a new SORGU or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sorgu_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sorgu_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help sorgu % Last Modified by GUIDE v2.5 08-Sep-2012 22:28:11

Page 104: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 104

% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sorgu_OpeningFcn, ... 'gui_OutputFcn', @sorgu_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before sorgu is made visible. function sorgu_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to sorgu (see VARARGIN) % Choose default command line output for sorgu handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes sorgu wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = sorgu_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global sorgu; global t1; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) t1=findobj(gcbf,'TAG','text1'); sorgu=questdlg('Giris Degeri Belirtiniz.','Giris','0','10','20','10'); set(t1,'string',sorgu)

Page 105: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 105

Programı çalıştırdığınızda 10 değeri varsayılan değer olarak görülmektedir.Siz 20 değeri seçtiğinizde ekran görüntüsü aşağıdaki şekildedir.

LİSTDLG Etkileşim Kutusu(Liste Görünüm Penceresi) Liste görünüm penceresi , bilgisayarda kayıtlı bir konum üzerinde görüntüleme,açma ve kaydetme özelliklerini taşır. Kullanımı; d = dir; str = {d.name}; [s,v] = listdlg('PromptString','Select a file:',... 'SelectionMode','single',... 'ListString',str) şeklindedir. Select a file Pencere başlığı Singleseçme imkanını belirtir. (Single-Tekli seçim ,Multiple-Çoklu seçim) StrGörüntülenecek matrisi belirtir. Örnek uygulama olarak çalışma klasörümüz work’u görüntüleyelim. function varargout = liste(varargin) % LISTE M-file for liste.fig % LISTE, by itself, creates a new LISTE or raises the existing % singleton*. % % H = LISTE returns the handle to a new LISTE or the handle to

Page 106: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 106

% the existing singleton*. % % LISTE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in LISTE.M with the given input arguments. % % LISTE('Property','Value',...) creates a new LISTE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before liste_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to liste_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help liste % Last Modified by GUIDE v2.5 08-Sep-2012 23:01:46 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @liste_OpeningFcn, ... 'gui_OutputFcn', @liste_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before liste is made visible. function liste_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to liste (see VARARGIN) % Choose default command line output for liste handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes liste wait for user response (see UIRESUME)

Page 107: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 107

% uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = liste_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) d = dir; str = {d.name}; [s,v] = listdlg('PromptString','WORK DİZİNİ',... 'SelectionMode','single',... 'ListString',str)

Not:Varsayılan olarak work klasörü olduğundan programı yukarıdaki şekilde yazarsanız work klasörü görülmektedir.

Page 108: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 108

Yazılımı aşağıdaki şekilde değiştirirseniz listeleme istediğiniz klasörü görüntüler. C: bölümündeki MATLAB701\toolbox klasörünü görüntelemek için aşağıdaki şekilde kodlama yapılır. cd C:\MATLAB701\toolbox %İlgili dizine giriş d = dir; str = {d.name}; [s,v] = listdlg('PromptString','Toolbox Dizini',... 'SelectionMode','single',... 'ListString',str) Bu durumda ekran görüntüsü aşağıdaki şekildedir.

Page 109: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 109

PRİNTDLG Etkileşim Kutusu(Yazdırma Penceresi) Figürü yazdırma penceresedir. Kullanılışı; Printdlg Printlg(-setup) printdlg('-crossplatform') Şeklinde kullanışları vardır. Örnek uygulamada 3 farklı yazdırma penceresini görebilirsiniz.

Page 110: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 110

Yazdırma programının yazdir.m dosysı aşağıdaki şekildedir. function varargout = yazdir(varargin) % YAZDIR M-file for yazdir.fig % YAZDIR, by itself, creates a new YAZDIR or raises the existing % singleton*. % % H = YAZDIR returns the handle to a new YAZDIR or the handle to % the existing singleton*. % % YAZDIR('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in YAZDIR.M with the given input arguments. % % YAZDIR('Property','Value',...) creates a new YAZDIR or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before yazdir_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to yazdir_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help yazdir % Last Modified by GUIDE v2.5 08-Sep-2012 23:40:52 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @yazdir_OpeningFcn, ... 'gui_OutputFcn', @yazdir_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end

Page 111: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 111

if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before yazdir is made visible. function yazdir_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to yazdir (see VARARGIN) % Choose default command line output for yazdir handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes yazdir wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = yazdir_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) printdlg % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) printdlg('-setup') % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) printdlg('-crossplatform')

Page 112: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 112

UİSETCOLOR Etkileşim Kutusu ( Renk seçim Penceresi) Program işleyişi esnasında, kullanıcının isteği doğrultusunda renk seçmesi istendiğinde kullanılan etkileşim kutusudur. Kullanılışı; Uisetcolor Şeklindedir. Örnek uygulama olarak bir statick text’in rengini değiştirelim. Programın renk.m dosyası aşağıdaki şekildedir. function varargout = renk(varargin) % RENK M-file for renk.fig % RENK, by itself, creates a new RENK or raises the existing % singleton*. % % H = RENK returns the handle to a new RENK or the handle to % the existing singleton*. % % RENK('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in RENK.M with the given input arguments. % % RENK('Property','Value',...) creates a new RENK or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before renk_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to renk_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". %% See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help renk % Last Modified by GUIDE v2.5 09-Sep-2012 00:09:33 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @renk_OpeningFcn, ... 'gui_OutputFcn', @renk_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before renk is made visible. function renk_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn.

Page 113: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 113

% hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to renk (see VARARGIN) % Choose default command line output for renk handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes renk wait for user response (see UIRESUME) % uiwait(handles.figure1); global red; global green; global blue; global t1; global r; % --- Outputs from this function are returned to the command line. function varargout = renk_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) t1=findobj(gcbf,'TAG','text1'); r=uisetcolor red=r(1,1) green=r(1,2) blue=r(1,3) set(t1,'backgroundcolor',[red green blue]) Programın ekran görüntüsü aşağıdaki şekildedir.

Page 114: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 114

UİSETFONT Etkileşim Kutusu( Karakter tipi penceresi) Program işleyisi esnasında; kullanıcının isteği doğrultusunda programda kullanılan stringlerin karakterlerini şekillendirmek için kullanılır. Kullanılışı; Uisetfont Şeklindedir. Örnek uygulama da; 8 puntoyla Ms Sans Şerif karakteriyle yazılmış olan; Aşırı Yük Koruması: Aşırı yük koruması,bir devrenin iletkenlerindeki aşırı yük akımları, iletken yalıtımını,terminalleri bağlantıları veya kabloların ve iletkenlerin yakınındaki hasar verecek şekilde aşırı sıcaklık artışına yol açmadan, bu akımları kesecek koruma cihazlarının bulundurulması demektir. Yazısını karakter tipi pencresinde seçtiğimiz düzende değiştiryoruz. Bunun için duzenle.m dosyası aşağıdaki şekildedir. function varargout = duzenle(varargin) % DUZENLE M-file for duzenle.fig % DUZENLE, by itself, creates a new DUZENLE or raises the existing % singleton*. % % H = DUZENLE returns the handle to a new DUZENLE or the handle to % the existing singleton*. % % DUZENLE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DUZENLE.M with the given input arguments. % % DUZENLE('Property','Value',...) creates a new DUZENLE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before duzenle_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to duzenle_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help duzenle % Last Modified by GUIDE v2.5 09-Sep-2012 00:36:05 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @duzenle_OpeningFcn, ... 'gui_OutputFcn', @duzenle_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1})

Page 115: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 115

gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before duzenle is made visible. function duzenle_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to duzenle (see VARARGIN) % Choose default command line output for duzenle handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes duzenle wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = duzenle_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) t1=findobj(gcbf,'TAG','text1'); yazi=get(t1,'string'); duzen=uisetfont; set(t1,duzen);

Page 116: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 116

Program çalıştırıldığındki ekran görüntüsü aşağıdaki şekildedir.

PAGESETUPDLG Etkileşim Kutusu(Sayfa Yapısı Penceresi) Çıktısı alınacak belgelerin veya şekillerin sayfa üzerindeki yerleşimlerini ve sayfa yapısını ayarlamaya yarar. Kullanılışı; Pagesetupdlg Şeklindedir. Örnek olarak sayfa.fig adında bir uygulama yapalım. Programın sayfa.m dosyası aşağıdaki şekildedir. function varargout = sayfa(varargin) % SAYFA M-file for sayfa.fig % SAYFA, by itself, creates a new SAYFA or raises the existing % singleton*. % % H = SAYFA returns the handle to a new SAYFA or the handle to % the existing singleton*. % % SAYFA('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SAYFA.M with the given input arguments. % % SAYFA('Property','Value',...) creates a new SAYFA or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sayfa_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sayfa_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help sayfa

Page 117: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 117

% Last Modified by GUIDE v2.5 09-Sep-2012 01:04:09 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sayfa_OpeningFcn, ... 'gui_OutputFcn', @sayfa_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before sayfa is made visible. function sayfa_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to sayfa (see VARARGIN) % Choose default command line output for sayfa handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes sayfa wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = sayfa_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) pagesetupdlg

Page 118: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 118

Program çalıştırıldığında ekran görüntüsü aşağıdaki şekildedir.

WAİTBAR Etkileşim Kutusu (Yükleme çubuğu) Yükleme çubuğu genelde bütün programlarda kullanılan , o sırada bir yükleme yapıldığını ve yükleme durumunu gösteren çubuktur. Kullanılışı; h = waitbar(0,'Lütfen bekleyiniz...'); for i=1:100, %işlemler waitbar(i/100) end close(h) şeklindedir. Örnek uygulama olarak programda yükleme durumunu belirtir bir Yükleme çubugu ekleyelim. Yukle.m programı aşağıdaki şekildedir. function varargout = yukle(varargin) % YUKLE M-file for yukle.fig % YUKLE, by itself, creates a new YUKLE or raises the existing % singleton*. % % H = YUKLE returns the handle to a new YUKLE or the handle to % the existing singleton*. % % YUKLE('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in YUKLE.M with the given input arguments. % % YUKLE('Property','Value',...) creates a new YUKLE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before yukle_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to yukle_OpeningFcn via varargin.

Page 119: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 119

% % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help yukle % Last Modified by GUIDE v2.5 09-Sep-2012 01:17:42 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @yukle_OpeningFcn, ... 'gui_OutputFcn', @yukle_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before yukle is made visible. function yukle_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to yukle (see VARARGIN) % Choose default command line output for yukle handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes yukle wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = yukle_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;

Page 120: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 120

global a; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) h = waitbar(0,'Lütfen bekleyiniz...'); for i=1:100, waitbar(i/100) end close(h) Programın ekran görüntüsü aşağıdaki şekildedir.

PRİNTPREVİEW Etkileşim Kutusu(Sayfa Önizleme Penceresi) Kullanıcı tarafından çıktısı alınacak olan belgenin sayfa üzerinde nasıl göründüğünü gösteren etkileşim penceresidir. Kullanılışı; Printpreview Şeklindedir. Bu etkileşim kutusu ayrıca sayfa yapısı (page setup) ve yazdırma penceresi (printdlg) penceresinide içermektedir.

Page 121: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 121

Örnek uygulama olarak sayfa_yap.fig isimli tasarımın sayfa_yap.m adlı dosyası aşağıdaki şekildedir. function varargout = sayfa_yap(varargin) % SAYFA_YAP M-file for sayfa_yap.fig % SAYFA_YAP, by itself, creates a new SAYFA_YAP or raises the existing % singleton*. % % H = SAYFA_YAP returns the handle to a new SAYFA_YAP or the handle to % the existing singleton*. % % SAYFA_YAP('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SAYFA_YAP.M with the given input arguments. % % SAYFA_YAP('Property','Value',...) creates a new SAYFA_YAP or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sayfa_yap_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sayfa_yap_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help sayfa_yap % Last Modified by GUIDE v2.5 09-Sep-2012 11:15:25 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sayfa_yap_OpeningFcn, ... 'gui_OutputFcn', @sayfa_yap_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before sayfa_yap is made visible. function sayfa_yap_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure

Page 122: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 122

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to sayfa_yap (see VARARGIN) % Choose default command line output for sayfa_yap handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes sayfa_yap wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = sayfa_yap_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) printpreview

Page 123: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 123

UİPUTFİLE Etkileşim Kutusu(Dosya Kaydetme Penceresi) Dosya kaydetme pencereleri alışılagelmiş durumda DOSYA menüsü altında bulunmaktadır.Matlabta dosya kaydetme komutu SAVE komutudur Bir tasarımda ayrı bir dosya kaydetme penceresi oluşturmak için uiputfile kullanılır. Kullanılışı; [fname,pname] = uiputfile('*.dosya_uzantısı',’pencere_başlığı’) şeklinde kullanılır. FnameDosya adını PnameDosya yolunu temsil eder. Bu komutla sadece açılacak olan pencerede dosya yolu ve dosya uzantısı belirlenmiş olur. Kayıt işleminin gerçekleşebilmesi için komut satırı ; [fname,pname] = uiputfile('*.dosya_uzantısı',’pencere_başlığı’) if fname ~=0 save([pname fname]) end şeklinde olmalıdır. Not:Tüm matlab dosya uzantılarıyla birlikte bir kaydetme penceresi oluşturulacak ise komut satırı aşağıdaki şekilde olur. [fname, pname] = uiputfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Dosyalari(*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-Dosyaları (*.m)'; ... '*.fig','Figurler (*.fig)'; ... '*.mat','MAT-Dosyalari (*.mat)'; ... '*.mdl','Modeller (*.mdl)'; ... '*.*', 'Tum Dosyalar (*.*)'}, ... 'KAYIT ET'); if fname ~=0 save([pname fname]) end şeklinde olmalıdır.

Page 124: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 124

UİGETFİLE Etkileşim Kutusu(Dosya Açma Penceresi) Dosya açma penceresi,dosya kaydetme penceresi ile benzer mantıkta çalışmaktadır.Matlabta dosya açma komutu LOAD komutudur. Kullanılışı; [fname,pname] = uigetfile('*.dosya_uzantısı',’pencere_başlığı’) şeklinde kullanılır. FnameDosya adını PnameDosya yolunu temsil eder. Bu komutla sadece açılacak olan pencerede dosya yolu ve dosya uzantısı belirlenmiş olur. Kayıt işleminin gerçekleşebilmesi için komut satırı ; [fname,pname] = uigetfile('*.dosya_uzantısı',’pencere_başlığı’) if fname ~=0 load([pname fname]) end şeklinde olmalıdır. Not:Tüm matlab dosya uzantılarıyla birlikte bir dosya açma penceresi oluşturulacak ise komut satırı aşağıdaki şekilde olur. [fname, pname] = uigetfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Dosyalari(*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-Dosyaları (*.m)'; ... '*.fig','Figurler (*.fig)'; ... '*.mat','MAT-Dosyalari (*.mat)'; ... '*.mdl','Modeller (*.mdl)'; ... '*.*', 'Tum Dosyalar (*.*)'}, ... 'DOSYA AÇ’); if fname ~=0 save([pname fname]) end şeklinde olmalıdır. Not:Matlab ta halihazırda bulunan Dosya kaydetme penceresi (uisave) ve Dosya açma penceresi (uiopen) komutları ilede yukarıdaki işlemler yapılabilir.

Page 125: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 125

Örnek uygulama olarak yukarıda açıkladığımız dosya açma ve dosya kaydetme pencerelerini göreceğiz.Burada ayrıca diğer 2 basit komutuda ekleyeceğim. dosya.fig olarak kaydettiğim tasarımın dosya.m adlı yazılım dosyası aşağıdaki şekildedir. function varargout = dosya(varargin) % DOSYA M-file for dosya.fig % DOSYA, by itself, creates a new DOSYA or raises the existing % singleton*. % % H = DOSYA returns the handle to a new DOSYA or the handle to % the existing singleton*. % % DOSYA('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DOSYA.M with the given input arguments. % % DOSYA('Property','Value',...) creates a new DOSYA or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before dosya_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to dosya_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help dosya % Last Modified by GUIDE v2.5 09-Sep-2012 12:23:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @dosya_OpeningFcn, ... 'gui_OutputFcn', @dosya_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before dosya is made visible. function dosya_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure

Page 126: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 126

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to dosya (see VARARGIN) % Choose default command line output for dosya handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes dosya wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = dosya_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [fname, pname] = uiputfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Dosyalari(*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-Dosyaları (*.m)'; ... '*.fig','Figurler (*.fig)'; ... '*.mat','MAT-Dosyalari (*.mat)'; ... '*.mdl','Modeller (*.mdl)'; ... '*.*', 'Tum Dosyalar (*.*)'}, ... 'KAYIT ET'); if fname ~=0 save([pname fname]) end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) uisave % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [fname, pname] = uigetfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Dosyalari(*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-Dosyaları (*.m)'; ...

Page 127: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 127

'*.fig','Figurler (*.fig)'; ... '*.mat','MAT-Dosyalari (*.mat)'; ... '*.mdl','Modeller (*.mdl)'; ... '*.*', 'Tum Dosyalar (*.*)'}, ... 'DOSYA AÇ'); if fname ~=0 save([pname fname]) end % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) uiopen Programın ekran görüntüleri aşağıdaki şekilde olacaktır.

Page 128: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 128

Şeklinde olacaktır.

Page 129: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 129

TASARIMA SAAT,TARİH,SES VE RESİM EKLEME Tasarıma saat ve tarih ekleme Tasarımınıza kullanım amaçlarına göre değişik eklentiler yapmanız mümkündür. Bunlardan ilki tasarıma saat ve tarih eklemektir.Bunun için aşağıdaki 3 komuttan yararlanabilirsiniz. Date Tarih bilgisini string olarak verir. Clock Tarih ve saat bilgisini nümerik matris olarak verir.[yy aa gg ss dd ss] Now Tarih ve saat bilgisini nümerik değer olarak verir. Bize gerekli olan komut Now komutudur. Matlab workspace’de >> tarih_saat=now tarih_saat = 7.3512e+005 >> tarih_saat=datestr(tarih_saat) tarih_saat = 09-Sep-2012 13:00:52 şeklinde icra edildiğini görebilirsiniz. Now komutu sonucu atanan değer 7.3512e+005 nümerik değeridir.Bu nümerik değeri datestr() komutu ile string değerine cevrildiğinde 09-Sep-2012 13:00:52 sonucu elde edersiniz. datestr(değişken,dateform) kullanılış şekli olmakla birlikte dateform listesi aşağıdaki şekildedir.

Page 130: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 130

Tasarıma ses ekleme Tasarımınıza wav uzantılı herhangi bir ses dosyasını yükleyebiliceğiniz gibi, ayrıca uyarı amaçlı BEEP sesinden faydalanılır. Tasarımınızda kullanacağınız wav uzantılı dosyalar için sound() komutundan faydalanılır. Sound komutuna işlevsellik kazandırmak amacıyla *.wav uzantılı ses dosyasını [y,Fs,bits] = wavread('ses_dosyası_ismi') sound (y,Fs,bits) şeklinde kullanmanız gerekir. Tasarıma resim ekleme Tasarıma resim eklemek için tasarımınızda resmi görüntülemek içn AXES nesnesine ihtiyaç duyacaksınız.Bir resmi Axes nesnesinde görüntülemek için 2 farklı yol izlenebilir.Bunlardan birini daha önce görmüştük. imread(‘dosya_ismi.dosya_uzantısı’) image() Böylece istenen resim dosyası axes figüründe görüntülenecektir. Tasarıma resim eklemeninb 2 yolu Loadimage.m ve saveimage.m fonksiyon dosyaları yardımıyla olacaktır. Loadimage.m ve saveimage.m dosylarını www.mathworks.com adresinden indirebileceğiniz gibi bu fonksiyonların aşağıdaki yazılımlarını yaparak ilgili başlıkta kayıt ederseniz, kullanabilirsiniz. Loadimage.m function [I,map]=loadimage [file,pathname]=uigetfile(‘*.*’,’Image’); buffer=pwd; cd(pathname); [I,map]=imread(file); cd(buffer) Burada r=loadimage komutu verdiğinizde açılacak pencereden ilgili resim seçilir.Böylece resim r matrisine atanmış olur. save resim.mat r komutu verdiğinizde work klasörüne resim.mat şeklinde atanmış olacaktır. image(resim) komutu verirseniz resmi görüntülemiş olacaksınız.

Page 131: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 131

Örnek Uygulama :Bu bölümde yukarıda anlatılan tüm eklentileri çalıştıran bir tasarım yapalım, Work klasörüne .wav uzantılı herhangi bir ses dosyası ekleyiniz.(opera.wav eklenmiştir.) Work klasörüne 2 adet farklı resim ekleyiniz.(pamukkale.jpg ve karakaya.jpg eklenmiştir.) Figür yüzeyini aşağıdaki şekilde ayarlayınız.İsmini eklenti.fig olarak kaydediniz.

Programın eklenti.m dosyası aşağıdaki şekildedir. function varargout = eklenti(varargin) % EKLENTI M-file for eklenti.fig % EKLENTI, by itself, creates a new EKLENTI or raises the existing % singleton*. % % H = EKLENTI returns the handle to a new EKLENTI or the handle to % the existing singleton*. % % EKLENTI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in EKLENTI.M with the given input arguments. % % EKLENTI('Property','Value',...) creates a new EKLENTI or raises the

Page 132: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 132

% existing singleton*. Starting from the left, property value pairs are % applied to the GUI before eklenti_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to eklenti_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help eklenti % Last Modified by GUIDE v2.5 09-Sep-2012 18:30:29 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @eklenti_OpeningFcn, ... 'gui_OutputFcn', @eklenti_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before eklenti is made visible. function eklenti_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to eklenti (see VARARGIN) % Choose default command line output for eklenti handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes eklenti wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = eklenti_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);

Page 133: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 133

% hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global t1; global tarih_saat; global resim1; global resim2; global r; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) t1=findobj(gcbf,'TAG','text1'); tarih_saat=now; tarih_saat=datestr(tarih_saat,0); set(t1,'string',tarih_saat); % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) beep % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [y,Fs,bits] = wavread('opera.wav'); sound (y,Fs,bits) % --- Executes on button press in pushbutton4. function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) resim1=imread('pamukkale.jpg'); axes(handles.axes1) image(resim1) % --- Executes on button press in pushbutton5. function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) r=loadimage; save resim.mat r; image(r)

Page 134: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 134

Programı çalıştırdığınızda saat ve tarih yazmakta, sesler çalmakta ve resimler görüntülenmektedir.Ekran görüntüsü aşağıdaki şekildedir.

Page 135: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 135

TASARIMDA .EXE DOSYALARINI ÇALIŞTIRMA Tasarımda, kullanıcının bilgisayarda kayıtlı .exe dosyalarını çalıştırmasını sağlayabilirsiniz. Bunun için matlab’ta açılacak olan programın .exe dosyasının , dosya yolu yazılarak önüne ! (ünlem) işareti konulur.Böylece dosya yolunun DOS komutu olarak çalıştırılması sağlanır. Öncelikle çalıştıracağımız programların dosya yolunu görüntüyelim. EXCEL için; C:\Program Files\Microsoft Office\Office10\EXCEL.EXE ADOBE ACROBAT için; C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe Program_ac.fig dosyası olarak kayıt ettiğimiz tasarımın program_ac.m adlı yazılım dosyası aşağıdaki şekilde olacaktır. function varargout = program_ac(varargin) % PROGRAM_AC M-file for program_ac.fig % PROGRAM_AC, by itself, creates a new PROGRAM_AC or raises the existing % singleton*. % % H = PROGRAM_AC returns the handle to a new PROGRAM_AC or the handle to % the existing singleton*. % % PROGRAM_AC('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PROGRAM_AC.M with the given input arguments. % % PROGRAM_AC('Property','Value',...) creates a new PROGRAM_AC or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before program_ac_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to program_ac_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help program_ac % Last Modified by GUIDE v2.5 09-Sep-2012 23:04:49 % Begin initialization code - DO NOT EDIT gui_Singleton = 1;

Page 136: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 136

gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @program_ac_OpeningFcn, ... 'gui_OutputFcn', @program_ac_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before program_ac is made visible. function program_ac_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to program_ac (see VARARGIN) % Choose default command line output for program_ac handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes program_ac wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = program_ac_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) !C:\Program Files\Microsoft Office\Office10\EXCEL.EXE % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) !C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe

Page 137: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 137

Programın ekran görüntüsü şağıdaki şekilde olacaktır.

TASARIMA MENÜ EKLENMESİ, MENÜ OLUŞTURULMASI VE SAĞ TUŞ MENÜSÜ GELİŞTİRMEK GUI tasarımında , tasarımınıza 2 farklı şekilde menü eklemek mümkündür. 1.yolStandart menü’yü tasarımınıza ekleyebilirsiniz. 2.yolKendi menünüzü oluşturup tasarımınıza ekleyebilirsiniz. Menü eklemeye geçmeden önce bir örnek yapalım. Aşağıda görülen şekilde menu.fig adlı bir tasarım oluşturun.(Siz istediğiniz resmi ekleyebilirsiniz)

Page 138: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 138

Görüldüğü gibi sadece bir resim görüntülenmekte. 1.yolStandart menü ekleme Figür yüzeyinin Property Inspector (özellikler Penceresi) ni açın.Figür yüzeyi üzerinde çift tıklarsanız açılır. Bu pencerede Menubar sekmesinde figüre ‘yi işaretleyin.Aşağıda bu görüntü görülmektedir.

Programı tekrar çalıştırdığınızda standart menünün eklendiğini göreceksiniz.

Eklenen Menu

Page 139: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 139

2.yolKendi Menümüzü oluşturmak. Öncelikle menu isimli tasarımınızın menubar özelliğini OFF durumuna getiriniz.Böylelikle tasarımımızı eski durumuna getirmiş oluruz. Menü oluşturmak için Menü Editör İkonuna basarak Menü Editör Penceresini açınız. Ekran görüntüsü aşağıdaki şekildedir.

Buradaki New Menü butonuna basarak aşağıdaki şekilde Unitled1 isimli seçeneği oluşturalım.

İsim

Etiket

Kısayol Tuşu

Callback

Alt menü ekleme

Page 140: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 140

Alt seçenek ekleme butonu yardımıyla ana menüye 3 adet alt seçenek ekleyiniz.

Bu durumda iken aşağıdaki ayarlamaları yapalım. Untitled 1 için Label : Menu Untitled 2 için Label : Sayfa Önizleme Callback: printprewiev Untitled 3 için Label : Sayfa Yapısı Callback: pagesetupdlg Untitled 4 için Label : Yazdır Callback: printdlg olarak yazın ve OK butonuna bastığınızda menünüz oluşmuş olacaktır.

Page 141: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 141

Programı çalıştırdığınızda aşağıdaki ekran görüntüsünü elde edersiniz.

NOT: Menü oluşturuken menü ağacı oluşturmaya dikkat edin.Benzer işlevlerdeki alt menüleri bir üst menüde toplamanızda son kullanıcı açısından yarar sağlayacaktır. TASARIMA SAĞ TUŞ MENÜSÜ EKLEMEK Sağ tuş menüsü kullanıcının sağ tuş ile ulaşabileceği menüleri gösterir.Tasarıma işlevsellik kazandırmak açısından kullanabilirsiniz.Örnek olarak yukarıda oluşturduğumuz menüleri sağ tuş menüsü olarak tasarlamak için,Menü Editör penceresinin CONTEXT MENUS sekmesinden yararlanılır.

Page 142: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 142

Benzer şekilde CONTEXT MENUS sekmesi üzerinde aşağıdaki şekilde ayarlayın. Untitled 5 Sağ Tuş ana menüsü (değiştirilmez) Untitled 6 için Label : Sayfa Önizleme Callback: printprewiev Untitled 7 için Label : Sayfa Yapısı Callback: pagesetupdlg Untitled 8 için Label : Yazdır Callback: printdlg

Bu işlemleri yaptıktan sonra Figür penceresinin özellikler penceresinden Uicontext Menu Penceresinden oluşturduğumuz menüyü işaretleyin.

Page 143: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 143

İlgili seçimleri yaptıktan sonra programı çalıştırdığınızda ekran görüntüsü aşağıdaki şekildedir.

Page 144: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 144

MATLAB İLE DERLEME Matlab GUI de oluşturduğunuz tasarımlarınızı icra edilebilir dosylar haline getirmeniz gerekmektedir.Böylece tasarımlarınız matlab programı olmayan herhangi bir bilgisayarad çalıştıraılabilir duruma gelmektedir. Matlab derleme işlemi için ,kendi derleyicisi olan LCC derleyicisini kullanır. Matlab Derleyicisinin kullanımının ayrıntılı bilgisini Matlab Help dosyasından edinebilirsiniz. Bize gerekli olan 2 adet kullanım mevcuttur. >>mcc –B sgl dosya.m C tabanlı grafik kütüphaneli uygulamalar oluşturur. >>mcc –B sglcpp dosya.m C++ tabanlı grafik kütüphaneli uygulamalar oluşturur. Bu işlemleri adım adım inceleyecek olursak.Daha önce basitce yaptığımız bir uygulama olan gizle.fig tasarımımızı icra edilebilir program haline getirmek için derleme işlemi yapalım. ADIM-1) Matlab komut satırında aşağıdaki komut uygulanır. >>mcc –B sgl gizle.m ADIM-2)Matlab komut satırında şağıdaki ifadeler sıralacaktır. Select a compiler: [1] Lcc C version 2.4 in C:\MATLAB701\BIN\WIN32\\..\..\sys\lcc [0] None Compiler: ADIM-3)Burada bilgisayarda kayıtlı olan derleyicileri sıralayacaktır.Gerekli olan derleyici Lcc C versiyon derleyici olduğundan; 1 değerini veriniz Compiler:1 (ENTER) Matlab derleme işlemi başlamış olacaktır.Derleme işlemi bittiğinde WORK klasörü altında gizle.exe icra edilebilir dosyasını göreceksiniz.

Page 145: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 145

Görüldüğü üzere derleme sonrası oluşan gizle.exe dosyası ve beraberinde oluşan dosyalar work klasörü içerisinde görülmektedir. YORUMLAR Bu dökümanda yer alan tüm bilgiyi okumanız halinde en basit uygulamadan, en kapsamlı uygulamalara kadar tüm tasarımlarınızı gerçekleştirebilecek bilgiye sahipsiniz demektir. Yazılımların kodlamalarında bilmeniz gereken tüm kodlar verilmiştir.Tasarımınız hangi işlevleri yapacak ise bu işlevleri gerçekleştiren MATLAB komutlarını öğrenmeniz gerekmektedir. Yazılımları kolaylıkla inceleyebilmeniz için renklendirmiş bulunuyorum.İlgili konuyu inceledikten sonra örnek uygulamaları kendiniz deneyerek kolayca benzer uygulamalar gerçekleştirebilirsiniz.Konuları yeterince görselleştirmeye çalıştım. http://www.mathworks.com/ sitesinden binlerce örneğe ve uygulamaya ulaşabilirsiniz. Veriler alınırken ilgili kaynaklar gösterilmiştir. Yardımcı olması dileklerimle TEŞEKKÜRLER. Harun YALÇIN ELEKTRİK ELEKTRONİK MÜHENDİSİ

Page 146: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 146

GERİ BESLEMELİ SİSTEMLERDE TRANSFER FONKSİYONU , GEÇİCİ VE SÜREKLİ REJİMLERİNİN İNCELENMESİ Öncelikle kontrol sistemlerinin tanındığı ve sitemler üzerinde çalışmaların nasıl yapıldığını bildiğinizi varsayarak bazı sistem verilerinin matlab ‘ta nasıl elde edildiğini ve birbirine dönüşümünü tablo halinde Matlab Help’te bulabilirsiniz.Burada 3 adet sistemi göz önüne alalım. Seri Bağlantılı Sistem

G(s) C(s) A=tf(Apay,Apayda); B=tf(Bpay,Bpayda); SYS(s)=series(A,B) çarpma işlemi uygulanır SYS=A(s)*B(s) Paralel Bağlantılı Sistem

G(s) C(s) A=tf(Apay,Apayda); B=tf(Bpay,Bpayda); SYS(s)=parallel(A,B) toplama işlemi uygulanır SYS=A(s)+B(s) Negatif Geri Beslemeli Sistem

G(s) C(s) A=tf(Apay,Apayda); B=tf(Bpay,Bpayda); SYS(s)=feedback(A,B,-1) Negatif Geri beslemeli sistem oluştur.

A(s)

B(s)

-

A(s) B(s)

A(s)

B(s)

+

Page 147: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 147

Herhangi bir sisteme bağlı kalmamak amaçlı pay ve payda katsayılarını figür yüzeyinden girş sağlayarak analizleri inceleyen bir tasarım yapacağız Figür penceresini aşağıdaki şekilde ayarlayın.

sistem.m adlı programlama dosyası aşağıdaki şekildedir. function varargout = sistem(varargin) % SISTEM M-file for sistem.fig % SISTEM, by itself, creates a new SISTEM or raises the existing % singleton*. % % H = SISTEM returns the handle to a new SISTEM or the handle to % the existing singleton*. % % SISTEM('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in SISTEM.M with the given input arguments. % % SISTEM('Property','Value',...) creates a new SISTEM or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before sistem_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to sistem_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help sistem

Page 148: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 148

% Last Modified by GUIDE v2.5 18-Sep-2012 19:58:04 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @sistem_OpeningFcn, ... 'gui_OutputFcn', @sistem_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before sistem is made visible. function sistem_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to sistem (see VARARGIN) % Choose default command line output for sistem handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes sistem wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = sistem_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; global e1, global e2, global e3, global e4, global apay, global apayda, global bpay, global bpayda, global resim, global g, global giris, global A,

Page 149: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 149

global B, global SYS, global cevap, axes(handles.axes1) resim=imread('geribesleme.jpg'); image(resim) function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');

Page 150: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 150

end function edit3_Callback(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit3 as text % str2double(get(hObject,'String')) returns contents of edit3 as a double % --- Executes during object creation, after setting all properties. function edit3_CreateFcn(hObject, eventdata, handles) % hObject handle to edit3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit4_Callback(hObject, eventdata, handles) % hObject handle to edit4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit4 as text % str2double(get(hObject,'String')) returns contents of edit4 as a double % --- Executes during object creation, after setting all properties. function edit4_CreateFcn(hObject, eventdata, handles) % hObject handle to edit4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

Page 151: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 151

% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) e1=findobj(gcbf,'TAG','edit1') apay=get(e1,'string') apay=str2num(apay) e2=findobj(gcbf,'TAG','edit2') apayda=get(e2,'string') apayda=str2num(apayda) e3=findobj(gcbf,'TAG','edit3'); bpay=get(e3,'string'); bpay=str2num(bpay) e4=findobj(gcbf,'TAG','edit4'); bpayda=get(e4,'string'); bpayda=str2num(bpayda) g=findobj(gcbf,'TAG','popupmenu1'); giris=get(g,'value') A=tf(apay,apayda) B=tf(bpay,bpayda) SYS=feedback(A,B,-1) if giris==1

Page 152: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 152

axes(handles.axes2) cevap=step(SYS) plot(cevap) elseif giris==2 axes(handles.axes2) cevap=impulse(SYS); plot(cevap) end

Page 153: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 153

ÖĞRENCİ DERS KAYIT UYGULAMASI Bir öğrencinin ders kayıtlarını yapabilmesi ve bunu kayıt altına alan bir uygulama yapalım. Figür penceresini aşağıdaki şekilde ayarlayalım.

Programın dersler.m dosyası aşağıdaki şekildedir. function varargout = dersler(varargin) % DERSLER M-file for dersler.fig % DERSLER, by itself, creates a new DERSLER or raises the existing % singleton*. % % H = DERSLER returns the handle to a new DERSLER or the handle to % the existing singleton*. % % DERSLER('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in DERSLER.M with the given input arguments. % % DERSLER('Property','Value',...) creates a new DERSLER or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before dersler_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to dersler_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES

Page 154: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 154

% Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help dersler % Last Modified by GUIDE v2.5 21-Sep-2012 23:01:26 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @dersler_OpeningFcn, ... 'gui_OutputFcn', @dersler_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before dersler is made visible. function dersler_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to dersler (see VARARGIN) % Choose default command line output for dersler handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes dersler wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = dersler_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output;

Page 155: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 155

% --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu2. function popupmenu2_Callback(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu2 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu2 % --- Executes during object creation, after setting all properties. function popupmenu2_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu3. function popupmenu3_Callback(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Page 156: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 156

% Hints: contents = get(hObject,'String') returns popupmenu3 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu3 % --- Executes during object creation, after setting all properties. function popupmenu3_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in popupmenu4. function popupmenu4_Callback(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu4 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu4 % --- Executes during object creation, after setting all properties. function popupmenu4_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles)

Page 157: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 157

% hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit1_Callback(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit1 as text % str2double(get(hObject,'String')) returns contents of edit1 as a double % --- Executes during object creation, after setting all properties. function edit1_CreateFcn(hObject, eventdata, handles) % hObject handle to edit1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit2_Callback(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit2 as text % str2double(get(hObject,'String')) returns contents of edit2 as a double % --- Executes during object creation, after setting all properties. function edit2_CreateFcn(hObject, eventdata, handles) % hObject handle to edit2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

Page 158: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 158

% --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) s1=findobj(gcbf,'TAG','popupmenu1'); d1=get(s1,'value'); s2=findobj(gcbf,'TAG','popupmenu2'); d2=get(s2,'value'); s3=findobj(gcbf,'TAG','popupmenu3'); d3=get(s3,'value'); s4=findobj(gcbf,'TAG','popupmenu4'); d4=get(s4,'value'); l1=findobj(gcbf,'TAG','listbox1'); ders=get(l1,'string') sinif=findobj(gcbf,'TAG','popupmenu5'); sira=get(sinif,'value'); if sira==2 switch d1 case 2 ders2=char(ders,'168 TEKNİK RESİM') set(l1,'string',ders2); case 3 ders2=char(ders,'180 TML.BİLG. TEKNOLOJİLERİ') set(l1,'string',ders2); case 4 ders2=char(ders,'181 MATEMATİK I') set(l1,'string',ders2); case 5 ders2=char(ders,'182 FİZİK I') set(l1,'string',ders2); case 6 ders2=char(ders,'183 ELEKTROTEKNİK I') set(l1,'string',ders2); case 7 ders2=char(ders,'101 ELEKTROTEKNİK II') set(l1,'string',ders2); case 8 ders2=char(ders,'122 MATEMATİK II') set(l1,'string',ders2); end end if sira==3 switch d2 case 2 ders2=char(ders,'273 ELEKTROMAGNETİK I') set(l1,'string',ders2); case 3 ders2=char(ders,'274 YÜKSEK MATEMATİK I')

Page 159: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 159

set(l1,'string',ders2); case 4 ders2=char(ders,'275 ÖLÇME') set(l1,'string',ders2); case 5 ders2=char(ders,'280 DEVRE TEORİSİ') set(l1,'string',ders2); case 6 ders2=char(ders,'282 MÜHENDİSLİK MEKANİĞİ') set(l1,'string',ders2); case 7 ders2=char(ders,'221 ELEKTRONİK') set(l1,'string',ders2); case 8 ders2=char(ders,'224 ELEKTROMAGNETİK II') set(l1,'string',ders2); end end if sira==4 switch d3 case 2 ders2=char(ders,'378 ELEKTRİK TESİSLERİ') set(l1,'string',ders2); case 3 ders2=char(ders,'380 ELEKTRONİK DEVRELER') set(l1,'string',ders2); case 4 ders2=char(ders,'382 GÜÇ ELEKTRONİĞİ') set(l1,'string',ders2); case 5 ders2=char(ders,'384 ELEKTRİK MAKİNALARI I') set(l1,'string',ders2); case 6 ders2=char(ders,'330 SİNYALLER SİSTEMLER') set(l1,'string',ders2); case 7 ders2=char(ders,'331 ELEKTRİK MAKİNALARI II') set(l1,'string',ders2); case 8 ders2=char(ders,'344 LOJİK DEVRELER') set(l1,'string',ders2); end end if sira==5 switch d4 case 2 ders2=char(ders,'469 MİKROİŞLEMCİLER') set(l1,'string',ders2); case 3 ders2=char(ders,'479 NONLİNEAR SİSTEMLER') set(l1,'string',ders2); case 4 ders2=char(ders,'470 HABERLEŞME TEKNİĞİ') set(l1,'string',ders2); case 5 ders2=char(ders,'480 SÜREÇ DENETİMİ') set(l1,'string',ders2); case 6 ders2=char(ders,'422 SAYISAL KONTROL')

Page 160: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 160

set(l1,'string',ders2); case 7 ders2=char(ders,'431 SAYISAL HABERLEŞME') set(l1,'string',ders2); case 8 ders2=char(ders,'401 BİTİRME PROJESİ') set(l1,'string',ders2); end end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) l1=findobj(gcbf,'TAG','listbox1'); set(l1,'string','') % --- Executes on button press in pushbutton3. function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) [fname, pname] = uiputfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Dosyalari(*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-Dosyaları (*.m)'; ... '*.fig','Figurler (*.fig)'; ... '*.mat','MAT-Dosyalari (*.mat)'; ... '*.mdl','Modeller (*.mdl)'; ... '*.*', 'Tum Dosyalar (*.*)'}, ... 'KAYIT ET'); if fname ~=0 save([pname fname]) end % --- Executes on selection change in popupmenu5. function popupmenu5_Callback(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu5 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu5 sinif=findobj(gcbf,'TAG','popupmenu5'); sira=get(sinif,'value'); switch sira case 2

Page 161: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 161

set(handles.text3,'visible','on') set(handles.popupmenu1,'visible','on') set(handles.text4,'visible','off') set(handles.popupmenu2,'visible','off') set(handles.text5,'visible','off') set(handles.popupmenu3,'visible','off') set(handles.text6,'visible','off') set(handles.popupmenu4,'visible','off') case 3 set(handles.text3,'visible','off') set(handles.popupmenu1,'visible','off') set(handles.text4,'visible','on') set(handles.popupmenu2,'visible','on') set(handles.text5,'visible','off') set(handles.popupmenu3,'visible','off') set(handles.text6,'visible','off') set(handles.popupmenu4,'visible','off') case 4 set(handles.text3,'visible','off') set(handles.popupmenu1,'visible','off') set(handles.text4,'visible','off') set(handles.popupmenu2,'visible','off') set(handles.text5,'visible','on') set(handles.popupmenu3,'visible','on') set(handles.text6,'visible','off') set(handles.popupmenu4,'visible','off') case 5 set(handles.text3,'visible','off') set(handles.popupmenu1,'visible','off') set(handles.text4,'visible','off') set(handles.popupmenu2,'visible','off') set(handles.text5,'visible','off') set(handles.popupmenu3,'visible','of') set(handles.text6,'visible','on') set(handles.popupmenu4,'visible','on') end % --- Executes during object creation, after setting all properties. function popupmenu5_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

Page 162: MATLAB_GUI_Türkçe_Kullanım_2012(güncel)

Matlab 7.0.1 GUI Tasarlama

Harun YALÇIN 162

Programın çalıştırdığımızda ekran çıktısı aşağıdaki şekildedir.