BASIC CODES FOR MATLAB
%To plot 3 cycles of sine wave of 20kHz and amplitude of 10
t= 0:0.0000001:0.00015;
y=10*sin(2*pi*20000*t);
plot(t,y);
title('Sine Wave')
xlabel('Time')
ylabel('Amplitude')
%To generate sound of sine wave having amplitude of 3 and frequency of
%20Khz
t= 0:0.0001:10;
y=3*sin(2*pi*20000*t);
wavplay(y,40000)
% ones of 4 x4
y = ones(4)
% ones % 1 row : 10 column
i = ones(1,10)
% zeros
% 1 row : 10 column
i = zeros(1,10)
% eye
% diagonal elements 1
i = eye(5)
% inverted eye % diagonal elements 0
i = ~eye(5)
% random numbers generation 5 x 5
i = rand(5)
% Size Command
y = size(t)
% Length Command
y = length(t)
% Assigning complex value
y = 7 + 6j
% Real and complex parts
g = real(y)
h = imag(y)
% Conjugate
k = conj(y)
%Generate the random matrix of 1x10 and check if any number is greater or
%equal to 0.5 make it 1
a= rand(1,10);
for m=1:10;
if a(1,m)>=0.5;
a(1,m)=1;
end
end
%How to make USER Defined function in MATLAB
Important points
1. Function is something that is called not run
2. File name and function name should same
3. Current directory
function dsp()
clc;
figure (10);
%How to make EXE. File of MATLAB
pcode dsp.m
mcc -m dsp.m