欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc

    • 资源ID:96698078       资源大小:1.82MB        全文页数:104页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc

    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, we 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 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 isant 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, click 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, lets 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 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 GUI 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, we 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 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 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 that 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 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 the 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, query 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 the 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 following 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 files 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 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 2008 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 had 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 need 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 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 u have explained the whole process. very clear! 10. on 22 Apr 2008 at 9:57 am 10Alfredo Huerta DuranMuy buena tu pagina, la estare consultando a menudo. De antemano te doy las gracias por la futuras visitas a tu tutorial. Alfredo Huerta11. on 13 Jun 2008 at 11:58 pm 11shanshui281Thank you very much !I learna lot of skills from this websit!12. on 22 Jun 2008 at 10:56 pm 12abhijit betalDear Sir,This tutorial helps me a lot. Thanks for it. Will you provide a tutorial on basic concept of the GUIDE ?With thanksAbhijit Betal13. on 23 Jun 2008 at 12:40 pm 13sathyaI used a series of checkboxes, each to plot the derivatives of a function.When I click on the checkbox, the plot sholud appear and when I unclick it, the plot should disappear. I used hold on on each checkbox callboxes, so that when I click all of them I should see all the plots. I tried using cla, but it clears the whole axes.If I uncheck the first checkbox, only the plot corresponding to it should disappear.Any help?14. on 01 Jul 2008 at 3:27 am 14ahmed badrcan i ask questioni have plot between eficiency and threshold and i get max efficiencycan i get threshold on max efficiency in gui of matlab code15. on 22 Jul 2008 at 2:55 pm 15ArashDear sir,I want to know how to capture the coordination of my graph?can you help me with that16. on 22 Jul 2008 at 5:01 pm 16Quan QuachArash,Can you elaborate on your question? I dont quite understand it.Quan17. on 23 Jul 2008 at 11:46 am 17ArashQuan,I want know is it any way to capture (x,y) of graph after plotting it,I mean after plotting a graph, I want to be able to click on graph and see dots on graph at my every (x,y), for exmple if I am plotting x=y, after plotting I want to be able to clicking on graph and then I get dots on graph at (1,1) (2,2)(-1,-1) and .I am not sure if there be anyawy to doing this?(I am really newcomber in Matlab GUI)I appreciate your help.Thank you,Arash18. on 23 Jul 2008 at 1:24 pm 18Quan QuachHi Arash,Use the data cursor icon to do this. See the last picture in this tutorial. The icon inside the right of the red box is the one you want to use. Click on this and then click on the curve.Quan19. on 24 Jul 2008 at 9:22 am 19ArashHi Quan,Thank you, I didnt get chance to try yet, I will let you know.appreciate your help.Thank you,Arash20. on 30 Jul 2008 at 7:55 am 20ArashHi,Thank you, it really helped, but is it any way to get coordination with out using tool bar, I mean is it any way to write function to do that, having more control on tool bar, for instance if we have to plot, so we have control some how to check coordination of either one at a time and cursar be regular cursar for other one?Thank you,Arash21. on 30 Jul 2008 at 8:10 am 21ArashHi,to give more, I am really new in Matlab but when I was reading tutorial for Radio Buttons, Toggle Buttons, and Button Group Panel I thought may be I can withset(handles.fontSelect_buttongroup,SelectionChangeFcn,fontSelect_buttongroup_SelectionChangeFcn);Create a function for getting coordination and then put push button for my plot so when I click that button or checkbox my cursar goes to getting coordination mode and get that instead of using toolbar.and I can put 2 different checkbox or button for 2 different plot in my program .Thank you,Arash22. on 30 Jul 2008 at 1:16 pm 22Paul DArash, a way to get the cursor position in your program without using the toolbar is as follows.l=datacursormode;lData=get(l,DataCursors);pos=get(lData,Position);you can also set the cursor position by doing the above in reverse with set commands. Test it out and youll see that it works pretty well.Paul23. on 30 Jul 2008 at 1:20 pm 23Paul DOr even l=datacursormode;pos=get(l.DataCursors,Position);24. on 30 Jul 2008 at 3:56 pm 24ArashHi paul,I creat 2 button for my 2 figure and put the code you gave me at call_back event of those but I get error.basically my goal is to control cursor some how when I click the button for that plot when I move my mouse on figure I get coordination of that point, just like a time I use toolbar.Arash25. on 31 Jul 2008 at 6:56 am 25Paul Dim not sure exactly at what you are trying to accomplish. Here is a little go through that you can just copy and paste into matlabs command prompt that will show the capabilities that I am discussing.x=0:.1:10;y=x2+2*x;graph=plot(x,y);l=datacursormode(graph);NOW goto the figure that just popped up and put a cursor position on the graph.NOW go back to the command prompt and typepos=get(l.DataCursors,Position)you will see that the variable pos holds the coordinates of the cursor.I do believe that this is the capability that you requested. This should be enough information to help you do whatever you want to do w/ captureing the coordinates of a cursor.26. on 10 Aug 2008 at 3:50 pm 26Ashutosh BhardwajHelped me a LOT with GUI programming. you guys should come out with a book !27. on 19 Aug 2008 at 1:57 am 27NrThank you very much for this tutorial!Matlabs help files are very confusing for me every time.These tutorials are very helpful.28. on 29 Aug 2008 at 3:03 pm 28RomanHi Quan Quach, do you have a tutorial about writing a GUI that allows signals, lets say, from a signal generator through serial port, to be displayed on the gui?Thanks29. on 29 Aug 2008 at 9:53 pm 29Quan QuachHi Roman,I havent dealt with data acquisition using MATLAB. So cannot help you there. Hopefully I will use it in the future and I can write a tutorial on it! Quan30. on 24 Sep 2008 at 5:19 am 30DEVANANDHello Quan,What a nice work this site is.I am an M-beginner.I have a doubt.I have a GUIDE application. Now I wanted to uncheck and check the checkboxes by clicking a pushbutton. How can it be done , plz help me.THANKS IN ADVANCE31. on 26 Sep 2008 at 2:28 pm 31sathyaDevanand,In the pushbutton callback, useset(handles.checkbox,Value,1)to check the checkboxand set(handles.checkbox,Value,0)to uncheck it.32. on 26 Sep 2008 at 2:34 pm 32Quan QuachDevanand,Sathya seems to hae beaten me to the punch. Thanks Sathya!Quan33. on 26 Sep 2008 at 2:37 pm 33sathyaThanks to you Quan.For the past six months I have been working on MATLAB and your tutorials have helped me a lot.34. on 26 Sep 2008 at 2:39 pm 34Quan QuachGlad you found our site helpful! Quan35. on 29 Sep 2008 at 6:29 pm 35LiamFantastic tutorial. I was amazed that I could get a small project working right off the bat based on this. However, I have 2 questions:1. Suppose I have two sliders and want to plot a point on the axes based on the values of the sliders. Which callback function should do the plotting? Whats the best way to approach this?2. Is there any way to turn off the automatic resizing of the axes? I want the axes to stay fixed regardless of the data being plotted.Thanks very much!Liam36. on 29 Sep 2008 at 8:51 pm 36Quan QuachHi Liam,Glad you found these tutorials helpful.for question 2:If you know what your x and y limits will be, you can do the following:axis(xmin xmax ymin ymax)For question 1:You would want to put your plotting code in the callback for the slider widget. Every time the slider value is changed, the callback is activated. Note that the slider callback is only activated each time you click the mouse. Good luck!37. on 29 Sep 2008 at 9:09 pm 37LiamThanks, Quan. Ideally, Id like the axes to update if any of the sliders are modified. Right now it only updates if the slider within which the plot code is written is clicked on. Is there some sort of refresh plot command?One more question, how do you retrieve the layout window of a

    注意事项

    本文(关于Matlab中的GUI的Plotting-Data-to-Axes精品资料.doc)为本站会员(封****n)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开