>> [ 1 2 3; 4 5 6 ]
ans =
1 2 3
4 5 6
>> x = [ 1 2 3 4 5 6 ]
X =
1 2 3 4 5 6
>> x.'
ans =
1
2
3
4
5
6
>> 2 : 0.2 : 4
ans =
2.00 2.20 2.40 2.60 2.80 3.00 3.20 3.40 3.60 3.80 4.00
>> 1:10
ans =
1 2 3 4 5 6 7 8 9 10
>> x = [ 1 2 3; 4 5 6 ]
x =
1 2 3
4 5 6
>> x(:, 1)
ans =
1
4
>> [1 2 3] * [4 5 6].'
ans =
32
>> [1 2 3; 4 5 6].^2
ans =
1 4 9
16 25 36
>> sum( log( abs(x) ) )
fs = 44100; % sampling rate
T = 1/fs; % sampling period
t = [0:T:0.25]; % time vector
f1 = 50; % frequency in Hertz
omega1 = 2*pi*f1; % angular frequency in radians
phi = 2*pi*0.75; % arbitrary phase offset = 3/4 cycle
x1 = cos(omega1*t + phi); % sinusoidal signal, amplitude = 1
plot(t, x1); % plot the signal
xlabel('Time (seconds)');
ylabel('x1');
title('Simple Sinusoid');
sound(0.9*x1, fs); % play the signal
phi = 2 * pi * 0.25; % 1/4 cycle phase offset
x1 = cos(omega1*t + phi); % sinusoidal signal, amplitude = 1
x2 = cos(2*pi*150*t + phi)/3; % sinusoidal signal, amplitude = 1/3
x3 = cos(2*pi*250*t + phi)/5; % sinusoidal signal, amplitude = 1/5
x4 = cos(2*pi*350*t + phi)/7; % sinusoidal signal, amplitude = 1/7
x5 = cos(2*pi*450*t + phi)/9; % sinusoidal signal, amplitude = 1/9
xcomplex = x1 + x2 + x3 + x4 + x5;
plot(t, xcomplex);
xlabel('Time (seconds)');
ylabel('xcomplex');
title('More Complex Signal');
sound(0.9*xcomplex, fs); % play the signal
function y = dumbfun(x, z)
% DUMBFUN An example Matlab function.
%
% Y = DUMBFUN(X,Z) doesn't do much. The Z parameter is optional
% and should either be a scalar or equal in size to X.
%
% By Gary P. Scavone, McGill University, 2004.
if nargin>1 & z>0,
if size(z) == [1 1] | size(z) == size(x),
y = 0.5.*x + z;
else
error('Parameter Z size error.');
return
end
else
y = 0.4.*x;
end
| ©2004-2013 McGill University. All Rights Reserved. Maintained by Gary P. Scavone. |