关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc
《关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc》由会员分享,可在线阅读,更多相关《关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc(104页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、MATLAB GUI Tutorial - Plotting Data to Axes 31 Oct 2007 Quan Quach 175 comments 25,632 views IntroductionIn this Matlab GUI tutorial, you will learn how to create and use the Axes component. The Axes component allows you to display graphics, such as graphs and images on your GUI. In this tutorial, w
2、e will create two axes on the GUI and plot some simple data onto it. In addition, we will include a reset button to clear the axes and we will also add the standard toolbar to allow the user to zoom, pan, and query the plot. This tutorial is written for those with little or no experience creating a
3、Matlab GUI (Graphical User Interface). If youre new to creating GUIs in Matlab, you should visit this tutorial first. Basic knowledge of Matlab is recommended. Matlab version 2007a is used in writing this tutorial. Both earlier versions and new versions should be compatible as well (as long as it is
4、ant too outdated). Lets get started!Create the Visual Aspect of the GUI1. First, open up Matlab. Go to the command window and type in guide.2. You should see the following screen appear. Choose the first option Blank GUI (Default).3. Click on and add two Axes components to the GUI figure. Next, clic
5、k on and add three Pushbutton components onto the GUI figure. 4. Double click the Axes component to bring up the Property Inspector. Change the Tag property to axes1, which should already be the default name. Additionally, make sure the other Axes components Tag property is named axes2. 5. Next, let
6、s modify the properties of the Pushbutton components. Double click on one of the Pushbutton components. Change the String property to Plot Axes 1, and the Tag property to plotAxes1_pushbutton, as shown below.Similarly, double click on the next pushbutton and change the String property to Plot Axes 2
7、 and change the Tag property to plotAxes2_pushbutton. Finally, double click on the final pushbutton and change the String property to Clear Axes and change the Tag property to clearAxes_pushbutton. 6. Heres what your figure should look like after you add the components and modify them.7. Save your G
8、UI wherever you please with your desired filename. Writing the Code for the GUIMatlab automatically generates an .m file to go along with the figure that you just put together. The .m file is where we attach the appropriate code to the callback of each component. For the purposes of this tutorial, w
9、e are primarily concerned only with the callback functions. You dont have to worry about any of the other function types.1. Open up the .m file that was automatically generated when you saved your GUI. In the Matlab editor, click on the icon, which will bring up a list of the functions within the .m
10、 file. Select plot1_pushbutton_Callback. Add the following code to the function:%selects axes1 as the current axes, so that %Matlab knows where to plot the dataaxes(handles.axes1)%creates a vector from 0 to 10, 0 1 2 3 . . . 10x = 0:10;%creates a vector from 0 to 10, 0 1 2 3 . . . 10y = 0:10;%plots
11、the x and y dataplot(x,y);%adds a title, x-axis description, and y-axis descriptiontitle(Axes 1);xlabel(X data);ylabel(Y data);guidata(hObject, handles); %updates the handles2. Similarly, we want to put the following code into the plot2_pushbutton_Callback:3. %selects axes2 as the current axes, so t
12、hat 4. %Matlab knows where to plot the data5. axes(handles.axes2)6. 7. %creates a vector from 0 to 10, 0 1 2 3 . . . 108. x = 0:10;9. %creates a vector 0 1 4 9 . . . 10010. y = x.211. 12. %plots the x and y data13. plot(x,y);14. %adds a title, x-axis description, and y-axis description15. title(Axes
13、 2);16. xlabel(X data);17. ylabel(Y data);guidata(hObject, handles); %updates the handles18. Next, we need to add some code to the clearPlots_pushbutton_Callback:19. %these two lines of code clears both axes20. cla(handles.axes1,reset)21. cla(handles.axes2,reset)guidata(hObject, handles); %updates t
14、he handles22. And finally, we need to add the following line of code to axes_tutorial_OpeningFcn:set(hObject,toolbar,figure);This line of code should be placed right before:guidata(hObject, handles);This line of code effectively adds the standard toolbar to the GUI, allowing the user to zoom, pan, q
15、uery the plot, and more. The standard toolbar and a brief description of the icons are shown below:23. Save your m-file!Run and Test the GUINow that weve completed both the visual and code aspects of the GUI, its time to run the GUI to make sure it works.1. From the m-file editor, you can click on t
16、he icon to save and run the GUI. Alternatively, from the GUIDE editor, you can click on the to launch the GUI. The following GUI should appear once you click the icon: 2. Go ahead and try pressing all of the buttons to make sure they work. If everything was done correctly, you should see the followi
17、ng plots. Also, you can use the icons that are within the red box to test out the other functions. 3. And thats it. Those are the basics of using the Axes component. You can explore the other options that the axes has to offer through the Property Inspector. This is the end of the tutorial. Source f
18、iles can be downloaded here.175 Responses to “MATLAB GUI Tutorial - Plotting Data to Axes”1. on 12 Jan 2008 at 12:48 pm 1Vaibhav BediaWhen i close MATLAB and start guide again my axes loses its TAG and hence becomes invisible.How do i solve this?2. on 20 Jan 2008 at 4:48 pm 2Alexnice one! U need to
19、write some more stuff for beginners 3. on 13 Feb 2008 at 3:59 pm 3SaikatThank you so much . I love your style and find your instructions very helpful.Going through the programs you have written for us, the beginners, I feel more confident of writing my own codes .Thank you once again .4. on 17 Feb 2
20、008 at 11:03 am 4TantyWhat a great tutorial.Im working on my final project, so this tutorial help me solve my problem writing the code for axes.Thanks.5. on 17 Mar 2008 at 9:57 pm 5lovejoyhow to plot a resultant vector in GUI ex.10N+5N6. on 26 Mar 2008 at 4:28 am 6nolavery nice tutorial.however i ha
21、d a query for you.when i do a zoom on the image.and click one pushbutton to make an action.the image return to its initial dimensions(i loose the zoom)could you help me on this subject?7. on 26 Mar 2008 at 12:37 pm 7Daniel SutoyoHi Nolagood question although I havent tried to code it yet, what you n
22、eed to do is to get the new axes info and store it somewhere.For example, your axes is called handles.axes1. You will have to use the get() and get the min,max axis on handles.axes1 and store in a variable for example myaxis.Now in your pushbutton function when you have a plot command, make sure you
23、 use the axis info in myaxis8. on 10 Apr 2008 at 3:43 am 8andyHow do we plot a graph where the function of graph is key in by user?I mean we can plot many different function of graph just by changing function?9. on 17 Apr 2008 at 11:42 am 9harshavery nice, it helped me a lot. Thanks, I love the way
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 关于Matlab中的GUI的Plotting-Data-to-Axes 精品资料 关于 Matlab 中的 GUI Plotting Data to Axes 精品 资料
限制150内