MATLAB-MATLAB ONLINE-PROGRAMMING-CODING-ENGINEERING

   INTRODUCTION TO MATLAB



 MATLAB is a high-level technical computing language equipped with a user-friendly interface. Its name stems from the words MATrix and LABoratory as it is based on the use of matrices. MATLAB is an extremely powerful tool useful for scientists and engineers from various disciplines. For example, MATLAB can be used in a wide range of applications, such as telecommunications, signal and image processing, control, mathematics, financial modelling, bioengineering, aeronautics, and many more.


M-FILES

 M-Files In order to write many commands that are executed all together, the program must be written in a text editor. In this editor, one can type all the needed commands to form a program, save the program, and execute it any time he or she wants. The text files are called M-files due to their suffice *.m. There are two categories of M-files: the Scripts and the Functions. Scripts 

SCRIPTS

Sripts are the M-files with MATLAB commands. Their name must have a .m suffix. Scripts are suitable for solving the problems that require many commands. The advantage of the scripts is that they are implemented very easily. Lab Task Write a script.



SCRIPT SAMPLED CODE

clc

 close all

 clear all %

 All commands that are % needed are typed in the % .m File

.Everything written % at the right of symbol % % is a comment and is not % taken into account t=-5:0.1:5; f=t.*cos(2*pi*t); plot(t,f);

FUNCTIONS

Functions Function are also M-files, That is, are files with extension .m and must be saved in the current Directory of MATLAB. The difference between functions and scripts is that a function accepts one or more input arguments and returns one or more output arguments. To declare that an M-file is a function the first line of the m file must contain the syntax definition. More specifically, the first line of the M-file must be of the form function[y1,y2,y3,…yn]=name{x1,x2,x3… xm}. The variable y1,y2,… yn are the outputs of the function while x1,x2,…xm are the input arguments. In case there is only one output, the square brackets are not necessary. The “name” specifies the name of the function. In order to execute a function, first the M-File is saved in Current Directory.



FUNCTION SAMPLED CODE

 function [sm,pro]=oper(A,B) %

 Program to understand the use of a function file

 % Institute Of Space TechnologY

 % EEE223 Signals and Systems % 

This function computes the % sum and the product of 2 matrices

 sm=A+B; pro=A*B;

Comments