The document discusses various MATLAB commands and functions for plotting, manipulating variables, and using logical operators. It provides examples of plotting single and multiple plots, extracting data from matrices, using relational and logical operators, and creating sine and cosine wave plots.
The document discusses various MATLAB commands and functions for plotting, manipulating variables, and using logical operators. It provides examples of plotting single and multiple plots, extracting data from matrices, using relational and logical operators, and creating sine and cosine wave plots.
• whos List known variables plus their size • help Ex: >> help sqrt Help on using sqrt • clear Clear all variables from work space • clear x y Clear variables x and y from work space • clc Clear the command window Plotting with MATLAB Plotting with MATLAB
>> second_vector = mydata ( : , 2) ; % Second one >> % and we can plot the data >> plot ( first_vector , second_vector ) • Suppose we want to plot multiple plots on a single set of axes. • We might try and do it as follows: • x = 0:0.01:1; • y1 = x.^2; • y2 = x.^3; • plot(x,y1,’blue’) • plot(x,y2,’red’) • But only the red one shows up! What’s the deal? Well, when you call plot, it will simply make the current figure using the entries of the latest plot call, overwriting what came before. To avoid this, we use the hold command, • x = 0:0.01:1; • y1 = x.^2; • y2 = x.^3; • hold on • plot(x,y1,’blue’) • plot(x,y2,’red’) • hold off MATLAB Relational Operators
• MATLAB supports six relational operators.
Less Than <
Less Than or Equal <= Greater Than > Greater Than or Equal >= Equal To == Not Equal To ~= MATLAB Logical Operators
• MATLAB supports three logical operators.
not ~ % highest precedence
and & % equal precedence with or or | % equal precedence with and
Only a single operator in
MATLAB!! • Create x as a vector of linearly spaced values between 0 and 2π. Use an increment of π/100 between the values. Create y as sine values of x. Create a line plot of the data. • x = 0:pi/100:2*pi; • y = sin(x); • plot(x,y) • Define x as 100 linearly spaced values between −2π and 2π. Define y1 and y2 as sine and cosine values of x. Create a line plot of both sets of data. • x = linspace(-2*pi,2*pi); • y1 = sin(x); • y2 = cos(x); • figure • plot(x,y1,x,y2)