Introduction to MATLAB
Matlab stands for Matrix Laboratory . This is a multi paradigm numerical computing environment and fourth generation programming language which is developed by MATHWORK. matlab also can be defined as “matlab is a software package for high-performance numerical computation and visualisation. It provides an interactive environment with hundreds of built-in functions for technical computation, graphics, and animation. Best of all, it also provides easy extensibility with its own high-level programming language”.
Because MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms creation of user interfaces and interfacing with programs written in other languages, including C, C++, C#, Java, Fortran and Python.
Introduction to MATLAB windows
- MATLAB Desktop:
matlab desktop is divided into four by namely: workspace, editor, current directory and command line
Workspace: Workspace consists of variables you declare during matlab session.
Current directory: Directory/ folder in which you are working
Command: Shows results of code/program.
2. Editor: Place to write your code or script
How to launch editor in matlab ?
Matlab editor can be opened as follows:
i. By typing a command in command window of matlab
>> edit file_name.m
Matlab editor will be launched.
ii. By clicking on new scritp button in matlab menu bar
To run this code, just hit run button from matlab menu bar or type a command run file_name.m in command window
3. Figure window:
The output of all graphics commands typed in the command window are flushed to the graphics or figure window, a separate gray window with (default) white background color . The user can create as many figure windows as the system memory will allow.
How to use MATLAB ?
Lets start with a simple example
Q. How to perform multiplication of two integers using matlab command window and editor?
Solution 1: Start your matlab session, command window can be found in the right side of maltab in default layout
>> a= 2; % Declaration of 1st integer
>> b = 4; %Declaration of 2nd integer
>> c = a*b
By using semicolon (;) we are not able to see these variables in command winodw
Solution 2: We need to write code in editor of matlab
a = 2;
b = 4;
c = a*b
save ( using save button form maltab menu bar) it with .m extension like example.m
Run it using run button form maltab menu bar or use command run file_name.m in command window. Check output at command window as well as workspace
How to run MATLAB without GUI ?
To run matlab without GUI we need to write a script as follows:
Step 1: Open you editor(vim, vi, gedit etc) and write these two lines
/home/usr/matlab/bin/matlab -nodisplay -nosplash -nojvm <example.m> output
Step 2: Save it with extension .sh (lets take script name as test.sh )
Step 3: Now we need to make it an executable script using chmod 777 test.sh command
Step 4: Submit your job using test.sh script, like ./test
Step 5: Check your output file for results
To learn about various matlab commands and operators refer this link