PLOTTING in MATLAB Lab sheet 4 20171439 By

PLOTTING in MATLAB Lab sheet 4 – 2017/1439 By: Elham Sunbu

EX: 1 Plot the Function sin(x) between 0≤x≤ 4π - Create an x-array of 100 samples between 0 and 4π. >>x=linspace(0, 4*pi, 100); - Calculate sin(. ) of the x-array >>y=sin(x); - Plot the y-array >>plot(x, y)

EX 2: Adding additional plots to a figure - HOLD ON holds the current plot - HOLD OFF releases hold on current plot - HOLD toggles the hold state » x = 0: . 1: 2*pi; » y = sin(x); » plot(x, y, 'b') » grid on » hold on » plot(x, exp(-x), 'r: *')

Plotting in Mat. Lab - Line plot FUNCTIONS: 1. Plot example:

Plotting in Mat. Lab 2. Plot wit line specification example:

Plotting in Mat. Lab - Plotyy ex:

Plotting in Mat. Lab - Plot 3 3 D ex:

EX: 3 Plotting in Mat. Lab

Discrete Graph – Stem Function

Stair Function
![EX: 4 Plot sin(x) and cos(x) over [0, 2π], on the same plot with EX: 4 Plot sin(x) and cos(x) over [0, 2π], on the same plot with](http://slidetodoc.com/presentation_image_h2/52a6dd963de55522ca5bb0d0d726b9b8/image-11.jpg)
EX: 4 Plot sin(x) and cos(x) over [0, 2π], on the same plot with different colures Method 1: >> x = linspace(0, 2*pi, 1000); >> y = sin(x); >> z = cos(x); >> hold on; >> plot(x, y, ‘b’); >> plot(x, z, ‘g’); >> xlabel (‘X values’); >> ylabel (‘Y values’); >> title (‘Sample Plot’); >> legend (‘Y data’, ‘Z data’); >> hold off;

EX: 5 con … y 2=cos(t); plot(t, y 2); plot(t, y, t, y 2) legend('sin', 'cos') plot(t, y) hold on plot(t, y 2, 'm') hold off subplot(2, 1, 2) plot(t, y) subplot(2, 1, 1) plot(t, y 2)

Thank You 13
- Slides: 13