containing a 1 (true) in each element for which all elements of the
corresponding column of matrix x are nonzero, and a 0 (false) otherwise.
find(x) Returns a vector containing the indices of the nonzero elements of
a vector x. Returns a vector containing
randn(state,s) Resets the state to s.
randn(state,0) Resets the generator to its initial state.
randn(state,J) Resets the generator to its J-th state for integer J.
randn(state,sum(100*clock) Resets the generator to a different state each time.
Histogram value in bin k: N(k), the number of samples with value xmin + (k 1)x
xmin + kx. This is also known as the absolute frequency.
The Matlab commands for generating and plotting a histogram are;
N = hist(x) Returns the r
Relative histogram of data2
Figure 7.5: Relative frequency histograms
Measures of central tendency
The mean and median describe the middle, or center, of the range of the ran
x(n) = x(1) x(2) x(k)
If X is a matrix withM rows and N columns with elements denoted x(m, n), m= 1,
2, . . . , M, n =
1, 2, . . . , N, then
The column sum y is the vector having elements y(n), n= 1, 2, . . . , N
x(m, n) = x(1
Random Numbers data1
0 50 100 150 200 250 300 350 400 450 500
Random Numbers data2
Figure 7.1: Random sequences
7.1 Maximum and Minimum
max(x) Returns largest value in vector x, or the row vector of largest elements
of each colu
Many engineering problems require the use of random numbers in the
development of a solution.
In some cases, the random numbers are used to develop a simulation of a complex
simulation can be tested over and over to analyze the results, with
truncation of this result. Similarly, the probability of a result in the range [1,2) is 0.5
can be mapped to 1b y truncation. The trunction function in Matlab is floor.
A script to simulate an experiment to flip a coin 50 times and display th
title(Random Numbers - data1),.
title(Random Numbers - data2),.
Other data analysis functions available in Matlab are described with the command
0 50 100 150 200 250 300 350 400 450 500
xc = [0 1]; % histogram centers
y = hist(coin,xc); % absolute frequency
xlabel(0: tails, 1: heads),.
title(Absolute Frequency Histogram for 50 Coin Flips)
The output displayed by the script:
Columns 1 through 12
The product y is the scalar
x(n) = x(1) x(2) x(N)
The cumulative sum y is the vector having elements y(k), k = 1, 2, . . . , N
x(n) = x(1) + x(2) + + x(k)
The cumulative product y is the vector having elements y(k), k = 1, 2, .
Hemisphere surface area: Ah = 2R2
Tank contains no dead air space.
Concrete slab with hermetic seal is provided for the base.
Cost of the base does not change appreciably with tank dimensions.
Express total volume in met
value computed in Section 7.3. The standard deviation can be confirmed by the
in Section 7.3. The computed values are not identical to the desired values because
values are due to a finite number of random samples. The computed
statement. The variables modified within the loop should include the variables in
or the value of the expression will never change. If the expression is always true (or
is a value that
is nonzero), the loop becomes an infinite loop.
More effective filtering functions and better implementations of filtering in Matlab
but these are beyond the scope of this presentation, which is intended as a short
8.6 Applied Problem Solving: Speech Signal
Selection statements in user-defined functions
Applied problem solving: speech signal analysis
8.1 Relational and Logical Operators
For relational and logical expressions:
Inputs: True is any nonzero number
False is 0
Thus, the variation of data2 is greater than that of data1, as we concluded from
the plotted data values.
7.4 Random Number Generation
Many engineering problems require the use of rand
500 = R2H +
Solving for H:
Express cost in dollars as a function of height and radius
C = 300Ac + 400Ah = 300(2RH) + 400(2R2)
Method: compute H and then C for a range of values of R, then find the minimum
value of C and
with the command following the end statement. If expression is a character string,
then a string
comparison is made with the case test expression. Multiple test expressions can be
separated, enclosed in braces cfw_. Only the first matching c
Temperature (degrees C)
Figure 8.2: Soda cooling curve
This cooling problem has an exact mathematical solution, which is determined by
update relationship as a differential equation and then
-1.0000 -0.6667 -0.3333 0.0000 0.3333 0.6667 1.0000
0.8415 0.9276 0.9816 1.0000 0.9816 0.9276 0.8415
Logical operators provide a way to combine or negate relational expressions.
42 + (1)2 + 32 = 5.1
In Matlab, norm(x) returns the Euclidean norm of row vector or column vector x.
For example, for x and y as defined above:
> nx = norm(x)
> ny = norm(y)
This inequality, also called the Cauc
4. Function M-files terminate execution and return when they reach the end of the
alternatively, when the command return is encountered.
Example 8.8 Step signal
The step signal is zero for negative time, stepping up to one for positive time
Nested if Statements
if statements may be nested, as shown in the following example:
i f d < 50
count = count + 1;
b = 0;
Assuming first that b and d are scalars, then if d<50, count is incremented by 1 and
d is displayed.
Vectors with the same number of elements can be added and subtracted in a very
Inner or Dot Product
The inner product (x, y), also referred to as the dot product x
The following script is written to do the following:
Represent the ship velocity as a vector S, the current velocity as a vector C, and
velocity as a vector W. Calculate the true-velocity vector T (velocity over the ocean
> A=3; B=[2 4 3]; C=[3 2; 6 1];
> [r c]=indmax(A)
> [r c]=indmax(B)
> [r c]=indmax(C)
In general, loops should be avoided in Matlab, as they can significantly increase the
of a program. Matla
to produce the word. An effective word recognition algorithm must capture this
change in sounds,
but the design of such an algorithm is beyond the material covered in this course.
Note that the
histogram has the appearance of a Gaussian or bell-shaped cur