Download presentation
Presentation is loading. Please wait.
Published byJoseph Mason Modified over 9 years ago
1
Plotting in MATLAB Rachel Davies Brittany Earnest Greg Fannon Nicholas Millan Khurram Najeeb
2
Overview Introduction to MATLAB Plotting in MATLAB o Introduction o Creating an m-file o Graphing and Labeling Troubleshooting
3
What is MATLAB? computer programming interface designed to complete complex calculations and iterations in seconds rapidly produces an accurate answer increases efficiency
4
Who Uses MATLAB? anyone can use it most often used by engineers, physicists and people who conduct heavy calculations free trial online, but full version is expensive
5
What is MATLAB Used to Calculate? most often used to: o complete iterations o solve complicated equations o simplify repetitive calculations o plot functions o complete regression, linear and non-linear
6
What is MATLAB Used to Calculate? most often used to: o complete iterations o solve complicated equations o simplify repetitive calculations o plot functions o complete regression, linear and non-linear
7
Intro to Plotting in MATLAB Audience: Users with little to no knowledge of MATLAB, and basic understanding of graphing functions. What you need: Access to MATLAB, function to be graphed in the form y = mx + b. In this example we will be graphing the function y = (1/3)x + 5 from x = -10 to x = 10.
8
Getting Started: Creating an M-file An M-file is what allows MATLAB to compile and execute multiple lines of code at once. To create a new M-file, click File-->new-->M-file A new window should pop-up.
9
Commenting Comments in MATLAB code make it easy to figure out what a given function is meant to do. Comment lines always begin with % –This signifies to the program that it should not run this line of code At the end of your comments, press enter twice For example:
10
Defining Your Function There are two steps involved in defining the function that one wishes to graph 1.Choosing the range of values over which the function will be graphed. a. Basic code: x = x i :x j; b. For this example, x = -10:10; c. Press enter 2. Entering your function: y = (1/3)*x + 5; a. Press enter Note: the semicolons at the end of each line mean that that line of code will not be displayed in the command window when the program is run.
11
Creating a Graph The code to create a plot is: plot(x,y) –This tells MATLAB to plot the values of variable x on the horizontal axis and the values of variable y on the vertical axis. Do NOT end this line with a semicolon –The plot just created will not be displayed if a semicolon is present. Press enter
12
Labeling: Giving Context to Data Adding labels to a plot allows one to instantly tell what the plot is meant to represent by looking at it. To give your graph a title, type: title('chart title here') Press enter To label the horizontal axis of the graph, type: xlabel('horizontal title here') Press enter To label the vertical axis of the graph, type: ylabel('vertical title here’) Press enter Note: The single quotes surrounding the titles are important because they tell MATLAB that what they enclose are words, not variables.
13
Running the Program In order to run one's program, one must first save it. To do this, click File-->Save As and then name your program and click save. Once it has been saved, click the Run button to run the program. The run button is a green arrow that looks like this: If you have done everything correctly, a plot of your function should open in a new window. If not, check the command window for any errors that may have occurred.
14
Troubleshooting ErrorCauseSolution The input character is invalid in MATLAB An invalid character was used in the entry Check code for misused quotes, punctuation, or letters with accents Undefined variable at ___The variable called at this position is not defined in the program code. Check that you a calling the proper variable: capitalization matters. Check that the variable is defined before you are calling it. Unexpected MATLAB expression An expression used is valid, but not one that MATLAB recognizes Check spelling of commands
15
Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.