MATLAB Flashcards
matlab install direcory?
Type, matlabroot in command window.
matlab: three dots … meaning?
Line continuation.
matlab: How to measure elapsed time?
using matlab ‘tic’ and ‘toc’.
‘tic’ starts a stopwatch. ‘toc’ gives the elapsed time in seconds.
‘tic’ will reset the stopwatch.
How do u find type of a variable in matlab?
class(varName)
— or —
whos your_variable
matlab: find dimentions of an array / matrix
size(your_array)
size(your_matrix)
class(your_matrix) gives the type of data elements contained in the matrix.
A column vector has N rows and one column. Dimension N x 1
A row vector has one row and N columns. Dimension 1 x N
whos your_array
gives all info (size, type) of array.
To get total num of elements
numel(your_matrix);
How to get info about machine architecture on which matlab is running on?
Type ‘computer’ on command window.
> [str, maxsize, endian] = computer;
What does a call to dsp.SineWave(…) return?
A column vector of sine wave samples, containing ‘SamplesPerFrame’ samples.
What does randi() function do?
Returns a matrix of random nums, in a given range, in a matrix of given shape.
randi(99, 1, 4): returns a 1x4 array of ints 1 … 99
randi([10, 20], 3, 4): returns a 3x4 matrix of ints 10 … 20
randi([10, 20], 3): returns a 3x3 square matrix of ints 10 … 20
randi([10, 20], ): returns one integer between 10 and 20
randi(range, shape)
How to draw scatter plot in matlab?
scatter([1 2 3], [1 4 9]);
scatter([1 2 3], [1, 8, 27], ‘*’, ‘r’)
scatter() needs both X & Y data arrays.
scatterplot() can work with only Y data array, X array is inferred.
matlab: How to do “Phase Shift Keying” (PSK) for given baseband data.
Use pskmod()
How does cat/concatenate of arrays/matrices work in matlab?
x = cat(dim, arr1, arr2);
dim is the dimension that will increase after matrices are put together.
A row array is of dimension 1xn
To cat two row arrays, dim=2, since num of columns will increase.
Two cat two column vectors, use dim=1, since number of rows will increase.
matlab:
x = 23;
what is type of x?
double
This is default of numeric variable.
matlab:
How do you create an uint16 type variable?
x = uint16(78);
other variable types are int16, uint8, int32, uint64,
single , double etc.
matlab: how to find minim value in an array?
min(array_name);
max is also available.
matlab: How to get absolute values of an array X?
y = abs(X);
y will have same dimensions as X, but each element will have absolute value of X elem. No negatives.
Matlab: How to find mean of an array X?
If X is a row or column vector,
mean(X) returns mean value.
If X is a matrix,
mean(X) returns an row vector, containing mean of each column.
Matlab: How do u open a file?
[fd, err_msg] = fopen(‘abc.data’, ‘r’);
data = fread(fd, inf, ‘int16’);
data will be a row vector of int16.
matlab: what is the last element of the array X.
X(end)
Give some examples of array slicing in matlab.
X(3 : 7)
X(5 : end)
X(1:2:end) % All odd index elements.
Step size is in the middle.
If the step size is negative, successive indices decrease.
X(end: -1: 1) % Reverse the array.
For matrices
one or both indices can be ranges,
A(2:4, 1:2)
A single : indicates 1:end
A(3,:) % Third row, all cols.
A(: , end) % last column