Home‎ > ‎

### MATLAB

MATLAB Tutorials:-

MATLAB
(MATRIX LABORATORY) is a numerical computing environment and 4th generation programming language. Developed by MathWorks, MATLAB allows matrix manipulation, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, Java and Fortran.

No body knows the exact power of MATLAB, if you learn this, your carrier will get boosted up.
You can simulate, calculate any equation almost anything through MATLAB.
No doubt MATLAB is very hard to learn, for those who are not dedicated and not passionate.

Original MATLAB Software is very costly and one can't purchase MATLAB, it is advised not to use pirated version of this
software either purchase Student Version of MATLAB from the MathWorks Site or you are advised to use FreeMAT(an open source software just like MATLAB), this can be used under GPL license for free.
It is available for all popular OS like Windows, Linux and OS X.

One can watch the FreeMAT startup Page on this link.

--> a = 2
a =
2
--> b = 4
b =
4
--> c = a +b;
--> c
ans =
6
-->

Type these commands in the Command Window and see the Result, if you don't understand whats going on just click here.

Now let us see how to plot a sinusoidal wave using FreeMAT, follow the same procedure for MATLAB environment also.

Now type edit in the command window this open the editor screen in the FreeMAT or in MATLAB environment.
Now type the commands shown below and save the file with the name "sine_wave.m". Note the ".m" extension, it is must for both i.e MATLAB and FreeMAT.
Basically there are two types of ".m" files available.
First one is known as Script File and other one is Function File, the ".m" file created in this example is script file, while the function file will be discussed later.
Now here is the code.To have a clear look, view this link.

#### Sine Wave

% This Script file Plots the Sine Wave with respect to time

clc; %Used to clear the screen (Just Clears the Screen)

clear; %Used to clear the Variable Window (This clears the Memory)

fSampling = 1000; %Sampling Frequency

t = 0:1/fSampling:1; %Time Interval

f = 3; %Carrier Frequency

sine_wave = sin(2*pi*f*t);

plot(t,sine_wave); %For Plotting the Sine Wave with Respect to time

xlabel('Time Axis');

ylabel('Sine Wave Amplitude');

title('Sine Wave Plot');

grid on;

And to view the output in FreeMAT just press F5 or click on Debug and then Press on Execute Buffer.

while to view the output in MATLAB just click on run button or press F5 key or press Debug Button and then Click Run.

Now we will see how to plot multiple figures on the same figure window in MATLAB environment.

First of all open the MATLAB editor from the command window by typing edit,  then type the following command into the editor.

clc;
clear;
fSampling = 1000;   % Sampling Frequency
t = 0:1/fSampling:1;
fCarrier = 3;       % Carrier Frequency
sine_wave = sin(2*pi*fCarrier*t); %Sine Wave
cosine_wave = cos(2*pi*fCarrier*t); %Cosine Wave
subplot(2,1,1)
plot(t,sine_wave,'m','LineWidth',2);
% Display Plot in Magenta Color Line Width of 2
xlabel('Time Axis \rightarrow');
ylabel('Sine Wave Amplitide \rightarrow');
title('\bf\itSine Wave Plot');
grid on;

subplot(2,1,2)
plot(t,cosine_wave,'r','LineWidth',2);
% Display Plot in Magenta Color Line Width of 2
xlabel('Time Axis \rightarrow');
ylabel('Cosine Wave Amplitide \rightarrow');
title('\bf\itCos Wave Plot');
grid on;