Unit 12 - Unit12 UnitObjectives Introduction ..Forexample

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Unit 12 Visualization in MATLAB Unit Objectives   Learning to Visualize your results. Creating 2D plots of your data. Creating 3D plots of your data. Formatting and presenting your data.   Introduction We now have two languages under our belt. Both have advantages and disadvantages. For example, you  would never write a program to operate a car's cruise control in MATLAB. You would use C++ and embed  your executable program on a chip inside the car. But if you were designing the car itself, you may use  MATLAB. It is easier to use and lots of functions are built in. In this section we are going to learn how to  visualize data generated using MATLAB which may further ease the design process. Visualizing solutions  graphically makes analyzing your data far easier, and MATLAB includes lots of visualization options. Task 1 - Creating and formatting simple 2D Plots. MATLAB offers a variety of commands to create and customize 2-dimensional plots. Before we go into  any detail, let's create a simple plot so you can see MATLAB in action. x = [-5 : 0.05 : 5 ]; y = 2*x.^2.*sin(x.^2); plot(x, y) Now type 'help plot' and review all the different options available for this function. Pay attention to the third  and optional string argument that lets you change the color and character plotted. Some of help section  may be a little hard to understand, but you should see a lot there you can use right away. Don't get too  intimidated that they include information for both beginner and advanced users. Even I don't understand  every thing in the help sections the first time I read them. Be sure to follow some of the links in the 'see 
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
also' section. Once you have done that, try out the following program, and mess around until you have a  pretty good idea how the whole thing works. x = [-5 : 0.05 : 5 ]; y1 = 2*x.^2.*sin(x.^2); y2 = 0.5*x.^3 - 3*x.^2 + 7*x + 32; plot(x, y1, 'ro') %hold on; figure(2); plot(x, y2, 'b-') grid on; xlabel('x-axis description here'); ylabel('y-axis description here'); title('My second graph in MATLAB!'); axis( [ -4 4 -100 100 ] ); text( 1.5, 10, 'Hello World!' ); I don't want to spend too much time talking about the plot function here, since 'help plot' tells you  everything you need to know. But there are a couple points of confusion and some features worth  mentioning. Remove the 'hold on' command and run the program again. What happened?  Now replace the 'hold on'  with the command figure(2). What happened?  It is important to note that the 'hold' and 'grid' commands toggle the hold state and grid's appearance  respectively. To avoid confusion, I prefer to use the more explicit 'hold on','hold off','grid on', and 'grid off'  commands.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern