This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CM0268 MATLAB DSP GRAPHICS 1 93 JJ II J I Back Close MATLAB Functions and Graphics We continue our brief overview of MATLAB by looking at some other areas: • MATLAB Functions: builtin and user defined • Using MATLAB Mfiles to store and execute MATLAB statements and functions • A brief overview of MATLAB Graphics CM0268 MATLAB DSP GRAPHICS 1 94 JJ II J I Back Close MATLAB functions MATLAB makes extensive use of functions (We have seen many in action already) • MATLAB provide an extensive set of functions for almost every kind of task. • Extensible through toolboxes — essentially a collection of functions. • Functions can operate on Scalars, Matrices, Structures, sometime in subtly different ways. • Soon we will learn how to create our own functions. CM0268 MATLAB DSP GRAPHICS 1 95 JJ II J I Back Close MATLAB Scalar Functions Certain MATLAB functions operate essentially on scalars: • These will operate elementbyelement when applied to a matrix . Some common scalar functions are: sin asin exp abs round cos acos log (natural log) sqrt floor tan atan rem (remainder) sign ceil CM0268 MATLAB DSP GRAPHICS 1 96 JJ II J I Back Close MATLAB Vector functions Some MATLAB functions operate essentially on a vector (row or column): • These will act on an mby n matrix ( m ≥ 2 ) in a columnbycolumn fashion to produce a row vector containing the results of their application to each column. • Rowbyrow operation can be obtained by using the transpose, ’ ; for example, mean(A’)’ . • You may also specify the dimension of operation using the second optional parameter. So mean(A, 1) works columnbycolumn and mean(A, 2) works rowby row . Some common vector functions are max sum median any min prod mean all sort std CM0268 MATLAB DSP GRAPHICS 1 97 JJ II J I Back Close MATLAB Vector Function Examples >> A = rand(4,4) A = 0.8600 0.8998 0.6602 0.5341 0.8537 0.8216 0.3420 0.7271 0.5936 0.6449 0.2897 0.3093 0.4966 0.8180 0.3412 0.8385 >> max(A) ans = 0.8600 0.8998 0.6602 0.8385 >> max(max(A)) ans = 0.8998 >> mean(A) ans = 0.7009 0.7961 0.4083 0.6022 >> mean(A’) ans = 0.7385 0.6861 0.4594 0.6236 >> mean(A’)’ ans = 0.7385 0.6861 0.4594 0.6236 >> mean(A, 2) ans = 0.7385 0.6861 0.4594 0.6236 CM0268 MATLAB DSP GRAPHICS 1 98 JJ II J I Back Close Matrix functions Much of MATLAB’s power comes from its matrix functions, many are concerned with specific aspects of linear algebra and the like (which does not really concern us in this module) Some common ones include: inv inverse det determinant size size rank rank MATLAB functions may have single or multiple output arguments. For example, rank() always returns a scalar: >> A A = 0.8600 0.8998 0.6602 0.5341 0.8537 0.8216 0.3420 0.7271 0.5936 0.6449 0.2897 0.3093 0.4966 0.8180 0.3412 0.8385 >> rank(A) ans = 4 CM0268 MATLAB DSP GRAPHICS 1 99 JJ II J I Back Close Return Multiple Output Arguments size , for example, always returns 2 values even for a vector: >> X = [1 2 3 4]; size(X) ans = 1 4...
View
Full
Document
This note was uploaded on 01/24/2012 for the course CM 0268 taught by Professor Davidmarshall during the Winter '11 term at Cardiff University.
 Winter '11
 DavidMarshall

Click to edit the document details