Presentation is loading. Please wait.

Presentation is loading. Please wait.

Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots.

Similar presentations


Presentation on theme: "Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots."— Presentation transcript:

1 Barbara/Pratik/Yu

2 Outline Matlab desktop M-files Variables Arrays Plots

3 Matlab Desktop Command Window Workspace Command History

4 M-files Save set of commands in a file Long code that requires more than a couple of commands Allows you to save code Extension that is used in matlab Examples -- Filename.m, anyname.m

5 How to create an m-file Click on File in upper left hand side Click on new Click on blank m-file Type code Save as

6 How to open/edit/close an m-file Click on file Click on open Then choose the m-file Make any changes needed to the file Click on save Then close the file by the x located in the upper right hand or File -> Close

7 Variable Assignment x=4 --Simple numerical assignment t = 10 – 4 -- Result of an operation y = pi --Special assignment z = 3 + y --Result of an operation with variables

8 Arrays Variables in Matlab can be accessed by indexing Every element of an array is designated by its unique row and column or a number pair The syntax is A(row#,column#)

9 Vectors Vectors are 1-dimensional arrays There are several ways to create a vector t= xmin:dx:xmax time= [ 1,2,3,4,5 ] t=linspace(xmin,xmax,dx) x=linspace(0,5,1)

10 Commands clear----Clears the workspace clc—clears the command window save – saves the file from the command window load—load the specified file from the command window

11 Plots plot(x,y) --plots 2-d data with x axis with values of x and y axis with values of y

12 Change plot line color For example plot(year,country,’b’) will make the plot line color blue Color options g green r red c cyan m magenta k black

13 Change Line Style For example plot(year, country,’-’) will make the line style solid Other line styles: -- dashed : dotted -. dash dot

14 Change plot marker plot(year, country, ’d’) diagonal cross Other marker options + vertical cross * star d diamond

15 Plot types Bar graph bar(x,y) Stem graph stem(x,y)

16 Annotating Plots To make a label for the x-axis xlabel(‘Year’) To make a label for the y-axis ylabel(‘Country’) To make a title for the Plot title(‘Gas Prices’)

17 Creating a Signal Create a continuous signal F(t)=A * sin(ωt)

18 Define a discrete time axis There are several ways to create the time axis—(creating a vector) t= xmin:dx:xmax time= [ 1,2,3,4 ] t=linspace(xmin,xmax,dx) x=linspace(0,100,5)

19 Plotting data Type in the following code (excluding the comments denoted by %): A=2; %assign value for variable A frequency=0.5; %assign value for variable frequency w=2*pi*frequency; %set value for w tmin=0; %assign starting time tmax=10; %assign end time dt=0.01; % assign increment time t=tmin:dt:tmax; %define time vector f=A*sin(w*t); %define the continuous time signal function plot(t,f,'r'); %plot with color of red. 'r'-red xlabel('time: t'); %set lable for x axis ylabel('signal: f(t)'); %set lable for y axis title('function of continuous time signal'); %set title

20

21


Download ppt "Barbara/Pratik/Yu. Outline Matlab desktop M-files Variables Arrays Plots."

Similar presentations


Ads by Google