65 views

Uploaded by greg4uathome

Attribution Non-Commercial (BY-NC)

- Fx-9860gii Soft En
- EE Course Scilab Online
- Geology & Geophysics Matlab Tutorial.pdf
- Matlab Miniguide
- 065 B Mathematics (for Blind)
- Matlab Tips
- LPile Plus Student Edition Documentation
- Matrix
- final exam review
- NESTbrochure-2010
- Algebra
- Biology Project
- Matlab Intro
- Mathcad_MatrixNotes
- 45_844
- MatrixMethod
- MATLAB Contents
- Syllabus MAM
- 16.08.10
- Javascript

You are on page 1of 8

MATLAB (MATrix LABoratory) is a Matrix Vector Oriented Programming language with significant

graphics capabilities

Programs in MATALB are called SCRIPT or COMMANDS

Programs are stored in Subdirectories as .m files

Subdirectories are linked to command window

control c aborts running script file (often indicated as ^c, but ^ is short for control key, not carrot)

format short (14 decimals) 3.14159265358979

example

>> help length

LENGTH Length of vector.

LENGTH(X) returns the length of vector X. It is equivalent

to MAX(SIZE(X)) for non-empty arrays and 0 for empty ones.

Operators + a+b (plus sign), addition operator

- a–b (minus sign), subtraction operator

* a*b (asterisk , multiply sign), multiplication operator

/ a/b (forward slant), division operator

^ a^b (carrot), exponentiation operator

+ a+b (plus sign), addition operator

- a–b (minus sign), subtraction operator

* a.*b (asterisk , multiply sign), multiplication operator

/ a./b (forward slant), division operator

^ a.^b (carrot), exponentiation operator

Other Notations % (percent sign) comment, anything to right is not read by matlab

% (percent sign) at top of m files is written to screen in response to help qwerty

; (semicolon) end row and suppress printing

: (colon) vector generation

… (ellipsis) continue line

‘ (single quote) transpose

( ) (left and right parenthesis) subscript enclosure

[ ] (left and right square bracket] matrix enclosure

, (comma) separator

pi represents π

i, j imaginary indicator

Inf represents ∞

NaN Not a number (eg 0/0)

zeros(1,3) 3-element row vector of zeros

zeros(3,4) 3 x 4 matrix of zeros

ones(1,3) 3-element row vector of ones (“1”)

ones(3,4) 3 x 4 matrix of ones (“1”)

eye(3,2) 3 x 2 matrix (3 rows, 2 columns)

with ones on diagonal

1 0

0 1

0 0

Variables: Variables are entered and presented as scalars, vectors, and matrices

All variables can contain real or complex values

Complex variables are denoted as x + j*y, or as x + i*y,

j and i are reserved variable names used as indicator

examples:

a=3.4 a=[3.4] scalar

b=3.4+j*2.6 b=[3.4+j*2.6] scalar

(no commas separating entries)

d=[1.5 2.7]’ 2 x 1 vector

d=[1.5;2.7] 2 x 1 vector

d=[1.5 2 x 1 vector

2.7]

dd=1:10 1 x 10 vector

ee=[1:5]’ 5 x 1 vector

figure(3) opens figure and labels it number 3

subplot(m n p) same

plot(y) plot y array on y axis against count index 1 2 3….length(y)

hold on sets toggle keeping previous plot

plot(x,y2,’:r’) plot y2 vrs x as dotted red line (see help plot)

hold off resets toggle keeping previous plots

axis(‘square’) sets axis box to a square box

text(x,y,[‘name’,num2str(var,’%7.2f%’)])

assigns value of “var” to text string

b blue . point - solid

g green o circle : dotted

r red x x-mark -. dashdot

c cyan + plus -- dashed

m magenta * star (none) no line

y yellow s square

k black d diamond

v triangle (down)

^ triangle (up)

< triangle (left)

> triangle (right)

p pentagram

h hexagram

PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point;

PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw a line.

subplot(2,1,1)

plot(0:100,cos(2*pi*(1:100)/50))

hold on

plot(0:100,sin(2*pi*(1:100)/50),’- -‘,linewidth’,2)

hold off

grid on

axis([0 100 -1.2 1.2])

title(‘cosine(2*\pi*(1:100)/50)’)

xlabel(‘counting index’)

ylabel(‘amplitude’

subplot(2,1,2)

plot(0:100,sin(2*pi*(1:100)/50))

hold on

plot(0:5:100,sin(2*pi*(1:5:100)/50),’o’)

hold off

grid on

axis([0 100 -1.2 1.2])

Common Math Functions

sqrt(x) square root of each element in array x

round(x) rounds each element of array x to nearest integer

fix(x) rounds each element of array x to nearest integer towards 0

floor(x) rounds each element of array x to next lower integer

ceil(x) rounds each element of array x to next higher integer

sign(x) +1 if x>0, -1 if x<0, 0 if x=0

rem(x,y) remainder r of x=q*y+r (modulus operator)

exp(x) e^x

log(x) log_e(x) or ln(x)

log10(x) log_10(x)

cos(x) cos(x) x in radians

tan(x) tan(x) x in radians

asin(x) inverse or arc sin(x)

acos(x) inverse or arc cos(x)

atan(x) inverse or arc tan(x)

atan2(y,x) inverse or arc tan(y/x) with angle in proper quadrant

complex operators

conj(aa) conjugates argument aa

real(aa) real part argument aa

imag(aa) imaginary part argument aa

abs(aa) absolute value of argument aa

angle(aa) atan2(imag(aa),real(aa))

polynomial operations

polyval(aa,x) evaluates polynomial with coefficients aa at argument values x

conv(aa,bb) convolves two polynomial sequence (product of two polynomials)

roots(aa) factors polynomial aa and lists roots

rand(1,n) uniform in 0-1 random numbers, row vector of length n

rand(2,4) 2 x 4 array containing uniform random entries

rand(5) 5 x 5 array containing uniform random entries

mean(aa) Mean of sequence in array aa

std(aa) standard deviation of sequence in array aa

interesting operators

fliplr(aa) reverses order of row elements

flipud(aa) reverses order of column elements

fftshift(aa) swaps first half of array with second half

hist(aa,m) histogram bins the elements of aa into m equally spaced cells

signal processing

fft(xx)

freqz(bb,aa)

zplane(bb,aa)

[bb,aa]= butter(nn,f1)

[bb,aa]= tcheby1(nn,r1,f1)

[bb,aa]= tcheby2(nn,r2,f1)

[bb,aa]= ellip(nn,r1,r2,f1)

filter(aa,bb,x)

sinc(t1:dt:t2)

hanning(nn)

kaiser(nn,beta)

programming

for n=1:1000

y(n) = cos(2*pi*0.1*n);

end

better MATLAB code

y=cos(2*pi*0.1*(0:999));

or

y=cos(2*pi*(0:0.1:99.9))

pause pauses script file, waits for user response (enter)

pause(tt) pause tt seconds, tt > .01

figure(2)

reg=zeros(1,1000);

reg(1:100)=sin(2*pi*(0:99)/100);

for nn=1:1001

plot(0:999,reg);

grid on

axis([0 1000 -1.1 1.1])

pause(0.01)

reg=[reg(1000) reg(1:999)];

end

frq = input('enter input frequency (cycles/interval): freq_in = ‘)

figure(3)

reg=zeros(1,1000);

frq = input('enter input frequency (cycles/interval): freq_in = ')

reg(1:100)=sin(2*pi*(0:99)*frq/100);

for nn=1:1001

plot(0:999,reg);

grid on

axis([0 1000 -1.1 1.1])

pause(0.01)

reg=[reg(1000) reg(1:999)];

end

Sample MATLAB Script File

figure(1)

subplot(2,1,1)

stem(0:42,hh,'linewidth',2)

grid on

axis([-5 45 -0.1 0.5])

title('Impulse Response')

xlabel('Normalized Time: (t/T)')

ylabel('Amplitude')

subplot(2,1,2)

plot((-0.5:1/1024:0.5-1/1024),fftshift(20*log10(abs(fft(hh,1024)))),'linewidth',2);

grid on

axis([-0.5 0.5 -70 5])

title('Frequency Response')

xlabel('Normalized Frequency: (f/f_S)')

ylabel('Amplitude')

plot((-0.5:1/1024:0.5-1/1024),fftshift(20*log10(abs(fft(hh,1024)))),'linewidth',2);

grid on

axis([-0.2 0.2 -0.2 0.2])

title('Zoom to Passband')

- Fx-9860gii Soft EnUploaded byAbdulrahman Nasereddin
- EE Course Scilab OnlineUploaded byRaúl Zura
- Geology & Geophysics Matlab Tutorial.pdfUploaded byquang
- Matlab MiniguideUploaded bybadro1980
- 065 B Mathematics (for Blind)Uploaded byPeeyoosh Jaiswal
- Matlab TipsUploaded bynnlice
- LPile Plus Student Edition DocumentationUploaded byfhlim2069
- MatrixUploaded byDeny Doank
- final exam reviewUploaded byapi-237333666
- AlgebraUploaded bycooboy112233
- Biology ProjectUploaded byBhagat Bhandari
- Matlab IntroUploaded byFachransjah Aliunir
- NESTbrochure-2010Uploaded byNaveenGoyal
- Mathcad_MatrixNotesUploaded bymojeebmashal
- 45_844Uploaded byprabhjot singh1
- MatrixMethodUploaded bysealg213
- MATLAB ContentsUploaded byJoseph John
- Syllabus MAMUploaded bytrustme77
- 16.08.10Uploaded byKaran Kapil
- JavascriptUploaded byt2vm
- Matrices and Arrays - MATLAB & Simulink.pdfUploaded byMakhdoom Ibad Hashmi
- Intro Tom at LabUploaded byasma246
- 4 1 Right Angled TrianglesUploaded byAudrey Lee
- MATLAB tut2Uploaded byNeeraj Agrawal
- Final Exam.pdfUploaded byShawn
- Active Pattern and Mutual ImpedanceUploaded byRidhwan Khalid Mirza
- Lecture 4 S16Uploaded bypascal joe
- 1-s2.0-S2212671612001618-mainUploaded byPedro Troncoso Acuña
- Notes for Cive1620 Large Type Part 1&2 Full2008 4upUploaded bysjeyarajah21
- MIT 18.022 5Uploaded bynislam57

- Hcm Process With BadiUploaded byAvik Poddar
- MagicQ Tutorial Part 3Uploaded byGregHavard
- ACN 2013-2014 (3)Uploaded bySneha Mehra
- ADL ModelUploaded bydevils365
- About IPcenterUploaded bySohail Adnan
- Multiprotocol Chip Interface for Industrial Communication an 01 EnUploaded bymachineman
- AutoCAD Plant 3D Complete GuideUploaded byMecanichal Steel
- PolygonsUploaded byedgardoqy
- 7.Standard Adapter Framework modules [AF_Modules]...pdfUploaded byankaiah_yadav
- It Ec 114 Assignment 1Uploaded byyawahab
- International Conference on EngineeringUploaded byAnchal Singh
- Uninformed SearchUploaded byOsaigbovo Timothy
- Analysis of the FLUTE Data Carousel PaperUploaded byShifaiz Mohamed
- Cs525b Mine StreamsUploaded byAkon Akki
- BioSense Webinar by HopperUploaded byPrabin Shakya
- SSRS-1Uploaded byvamsi reddy
- [NEW] 1Z0 808 New Updated Exam Questions Braindump2go 100% Guarantee Pass Oracle 1Z0 808 ExamUploaded bySharjeel
- An Introduction to the Finite Element Method-COMSOLUploaded byJUAN4201
- The SELinux Notebook the Foundations 3rd EditionUploaded byAnonymous pcdyTAlh
- AWS B1.11M-B1.11-2015 Download HereUploaded bySrithish Sridharan
- Teklabook_Lesson7_SteelDetailingUploaded byMrsonso
- Modal analysis on civil engineering .pdfUploaded byar_frank
- ASSASSIN’S CREED UNITY 100% Complete Save Game PCUploaded byunitysavegame
- BR100_FT_SSHR_Setup_HRMS SETUP.docUploaded byanishokm2992
- Curriculum Vitae - Mario FalangaUploaded bymario
- How to Earn Money via Different Chatting PlatformUploaded byShivani Pandey
- 1140235bUploaded bydbinnie
- Action Plan for Capstone 3Uploaded byjocansino4496
- KAPUploaded byAnass Az-Zahra
- 1Uploaded byDarshan Minnanda