V R SIDDHARTHA ENGINEERING COLLEGE
EEE DEPARTMENT
MATLAB Applications to
electrical Engineering
S.V.R.LAKSHMI
KUMARI
P.VENKATESH
ASSISTANT PROFESSOR
ASSOCIATE PROFFSSOR
10/9/15 03:16:28 PM
MATLAB PRESENTATION
Introduction to MATLAB
MATLAB Basics
Vectors and Matrices
Loops
Plots
Examples
Simulink
Modelling examples
MATLAB
SIMULINK
CONTENTS
Introduction to MATLAB
MATLAB Basics
Vectors and Matrices
Loops
Plots
Examples
MATLAB
INTRODUCTION
MATLAB has been developed by Math Works ,It is a powerful
software package used for high performance scientific numeric
computation ,data analysis and visualization
MATLAB stands for MATrix Laboratory
MATLAB provides matrix as one of the basic elements. It provides
basic operations like addition , subtraction , multiplication by use of
simple mathematical operators
Programs can be run step by step, with full access to all variables,
functions etc
10/9/15 03:16:29 PM
MATLAB PRESENTATION
We need not declare the type and size of any variable in advance and
MATLAB is case sensitive and so we have to be careful about the case of
variables while using them in our program
MATLAB gives an interactive environment with hundreds of reliable and
accurate built in functions. These functions help in providing the solutions
to a variety of mathematical problems including matrix algebra ,linear
systems ,differential equations ,optimization, nonlinear systems and other
scientific and technical computations
It facilitates access to FORTRAN and C codes by means of external
interfaces
Rows and columns are always numbered starting at 1
MATLAB matrices are of various types to hold different
kinds of data (usually floats or integers)
A single number is really a 1 x 1 matrix in MATLAB
Any matrix can be assigned to any variable
Advantages and Disadvantages of
MATLAB
Advantages:
Ease of Use
Platform Independent (All versions of Windows, Linux, Unix, Mac.)
Predefined Functions and Toolboxes
Device-Independent Plotting
Graphical User Interface
Matlab compiler
Disadvantages:
Interpreted programming language, slower than C++
and Fortran.
MATLAB BASICS
Introduction to Matlab
MATLAB Basics
Vectors and Matrices
Loops
Plots
MATLAB examples
Workspace
Command
History
10/9/15 03:16:29 PM
Change the current
directory to the
location of your
Matlab file at
startup
Command Window
MATLAB PRESENTATION
MATLAB Windows
MATLAB desktop
Workspace: All the information and details of every variable entered into the
command window is displayed here.
Command History : stores history of every command.
Command window: Every operation which we want to
be entered in command window.
perform is to
Editor Window :This window is used to write any program, which
includes many command statements. By using this window one can
edit any previously written command.
Figure Window :All the figures are shown in a separate figure window.
10
3 ways to open a new m-file using MATLAB editor
1.
Type >> edit myprogram.m at the command prompt
2.
Click on the blank page on MATLAB main window toolbar
3.
Click File New M-file
10/9/15 03:16:29 PM
MATLAB PRESENTATION
11
Variables
1.
2.
3.
In MATLAB environment, every variable is an array or matrix
Once a variable is entered into the system, you can refer to it later
When an expression returns a result that is not assigned to any variable, the system
assigns it to a variable named ans, which can be used later
4. You can have multiple assignments on the same line
Ex : a = 2; b = 7; c = a * b
5. Thewhocommand displays all the variable names you have used
6. Thewhoscommand displays little more about the variables
7. A valid variable name starts with a letter, followed by letters, digits,
or underscores
8. Avoid creating variables with the same name as a function (such
asi,j,mode,char,size, andinf etc.)
9. Check whether a proposed variable name is already in use with
theexistorwhichfunction.existreturns0if there are no existing
variables, functions, or other artifacts with the proposed name
Predefined variables
Break,Case,Catch,continue,else,elseif
end,for,function,global,if,otherwise,return,
switch,try ,while,pi,j,I,ans,NaN,inf etc
Creating Vectors
Create vector with equally spaced intervals
>> x=0:0.5:pi
x =
0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
Create vector with n equally spaced intervals
>> x=linspace(0, pi, 7)
x =
0 0.5236 1.0472 1.5708 2.0944 2.6180 3.1416
Equal spaced intervals in logarithm space
>> x=logspace(1,2,7)
x =
10.0000
14.6780
21.5443
68.1292 100.0000
31.6228
46.4159
Some Built-in functions
mean(A):mean value of a vector
max(A), min (A): maximum and
minimum.
sum(A): summation.
sort(A): sorted vector
median(A): median value
std(A): standard deviation.
det(A) : determinant of a square
matrix
dot(a,b): dot product of two vectors
Cross(a,b): cross product of two vectors
Inv(A): Inverse of a matrix A
Arithmetic Operations and
Precedence
Operation
Algebraic
Matlab
Form
Scalar
addition
a+b
a+b
subtraction
ab
ab
multiplication a x b
a*b
division
ab
a/b
Exponentiation
ab
a^b
Precedence
Operation
1
Parenthesis, innermost first.
Exponentiation, left to right
Multiplication & division, left to right
Addition & subtraction, left to right
2^3^4 equals (2^3)^4
3+4 equals (2-3)+4
10/9/15 03:16:29 PM
2/3*4 equals (2/3)*4
MATLAB PRESENTATION
216
Function
exp(x)
log(x)
log10(x)
sqrt(x)
10/9/15 03:16:29 PM
Description
Exponential (ex)
Natural logarithm
Base 10 logarithm
Square root
MATLAB PRESENTATION
17
Trigonometric Operations
Functio
n
Description
Computes the sine of x, where x is in
sin(x)
radians.
Computes the cosec of x, where x is in
csc(x)
radians.
Computes the sin of x, where x is in
sind(x)
degrees.
Computes the arcsine or inverse sine
asin(x)
of x, where x is in radians.
Computes the hyperbolic sine of x,
sinh(x)
where x is in radians.
atanh(x
ComputesMATLAB
thePRESENTATION
inverse hyperbolic
10/9/15 03:16:29 PM
18
Complex Number Functions
Functio
n
Description
Computes the complex conjugate of
the complex number x. Thus, if x is
conj(x)
equal to a+ib, then conj(x) will be
equal to a-ib.
Computes the real potion of the
real(x)
complex number x.
Computes the imaginary potion of the
imag(x)
complex number x.
Computes the absolute value of
abs(x)
magnitude of the complex number x.
angle(x
ComputesMATLAB
thePRESENTATION
angle of the complex 19
10/9/15 03:16:29 PM
Commands for Managing
Variables
Comman
Description
d
clear
Removes all variables from the
memory.
clear a, Clears only variables a and b from
b
memory.
who
Lists the variables currently in
workspace.
whos
Displays a lists of the variables
currently in the memory and their
size together
with information about
10/9/15 03:16:29 PM
MATLAB PRESENTATION
20
Examples
>> x=1:3
x=1
>> exp(x)
ans = 2.7183 7.3891 20.0855
>> log(x)
ans = 0 0.6931 1.0986
>> sqrt(x)
ans = 1.0000 1.4142 1.7321
Addition,substraction and division of complex
numbers
clc;
clear;
z1=1+2i;
z2=3+4i;
z3=z1+z2
z4=z1-z2
z5=z1*z2
z6=z1/z2
abs(z2)
angle(z3)
Output
z3 = 4.0000 + 6.0000i
z4 = -2.0000 - 2.0000i
z5 = -5.0000 +10.0000i
z6 = 0.4400 + 0.0800i
ans =5
ans = 0.9828
Solve the following examples using
MATLAB
10/9/15 03:16:29 PM
MATLAB PRESENTATION
24
10/9/15 03:16:30 PM
MATLAB PRESENTATION
25
Program to calculate trignometric
values
Program:
x=0:30:180;
y=[sind(x);cosd(x);tand(x);cscd(x);secd(x);c
otd(x)]
z=[x;y]
10/9/15 03:16:30 PM
MATLAB PRESENTATION
26
Solving linear equations
A System of simultaneous linear equations is
written , AX =B
A is a given square matrix of order n , B is a
given column vector of n components and X is
an unknown column vector of n components
we have learn that the solution to AX =b ,can
be written as X=A-1b ,where A-1 is the inverse
of A
10/9/15 03:16:30 PM
MATLAB PRESENTATION
27
Example :
10/9/15 03:16:30 PM
MATLAB PRESENTATION
28
Solutions to Systems of Linear
Equations (cont)
Solution by Matrix
Inverse:
Ax = b
A-1Ax = A-1b
x = A-1b
Ax = b
>> A = [ 3 2 -1; -1 3 2; 1
-1 -1];
>> b = [ 10; 5; -1];
>> x = inv(A)*b
x=
-2.0000
5.0000
Answer:
x =-6.0000
-2, x = 5, x = -6
2
The solution to the equation
can be computed using left division.
MATLAB:
Solution by Matrix Division:
MATLAB:
>> A = [ 3 2 -1; -1 3 2; 1 -1 -1];
>> b = [ 10; 5; -1];
>> x = A\b
x=
-2.0000
5.0000
-6.0000
Answer:
x1 = -2, x2 = 5, x3 = -6
NOTE:
left division: A\b b A right division: x/y x y
linsolve command
Solve the system:
5 x 2 y 3 z 3
4 y 3z 2
x y 9 z 60
A*S=B
MATLAB Code:
>> A=[5,-2,-3;0,4,3;1,-1,9];
>> B=[-3,-2,60]';
transpose ()
>> S=linsolve(A,B)
S=
1.0000
-5.0000
6.0000
10/9/15 03:16:30 PM
% Note vector
Solve command
The solve command used to solve quadratic equations. The
function returns the roots of the equation
Example :
MATLAB CODE
1)Quadratic equation x2-7x +12
=0
OUTPUT
s=
3
4
>> Eq = X^2-7*X+12;
>>S= Solve(Eq);
(or)
solve('x^2-7*x+12=0')
2) X4-7X3+3X2-5X+9=0
>> Eg= X^4-7*X^3+3X^25X+9=0;
>>S=solve(Eg);
S= 6.6304 ,1.06 ,-0.34 1.077
and -0.34 + 1.077
EX:
syms a b c x
fun=a*x^2+b*x+c;
solve(fun,x)
Output:
ans =
-(b + (b^2 - 4*a*c)^(1/2))/
(2*a)
-(b - (b^2 - 4*a*c)^(1/2))/(2*a)
Expandand
theCollectcommands
Theexpandand thecollectcommand expands and collects an
equation respectively. The following example demonstrates the
concepts
MATLAB Code :
10/9/15 03:16:30 PM
MATLAB PRESENTATION
33
Factor command :
Thefactorcommand factorizes an
expression and
thesimplifycommand simplifies an
expression.
MATLAB :code
Examples
Answer
factor(x^3 - y^3)
(x - y)*(x^2 + x*y + y^2)
factor([x^2y^2,x^3+y^3])
[ (x - y)*(x + y), (x + y)*(x^2 x*y + y^2)]
simplify((x^4-16)/
(x^2-4))
x^2 + 4
10/9/15 Simplify((x^303:16:30 PM
MATLAB
PRESENTATION
X^2+x*y+y^2
34
Polyval command:
POLYVAL command Evaluates polynomial in a matrix
sense
Ex 1:
>> a=[1 2 3];
>> polyval(a,1)
ans =6
% polynomial X2 + 2X +3
% polynomial is evaluated at 1
Ex 2:
>>a=[1 2 3]
>>b= 1:5
>>C=polyval(a,b)
Output :
C=[6 11 18 27 38]
10/9/15 03:16:30 PM
MATLAB PRESENTATION
35
Polyval and poly
EX :(with breakpoints)
clc
clear
p=[1 2 1]
x=-2:1:2
y=polyval(p,x)
plot(x,y)
r=roots(p)
q=poly(r)
Diff command
MATLAB provides thedifcommand
for computing symbolic derivatives
Examples :
MATLAB CODE
ANSWER
syms t
f = 3*t^2 + 2*t^(-2);
diff(f)
6*t - 4/t^3
f = x*exp(-3*x);
diff(f, 2)
9*x*exp(-3*x) - 6*exp(3*x)
10/9/15 03:16:31 PM
MATLAB PRESENTATION
37
Integration:
MATLAB Code :
syms x
int(2*x)
ans = x^2
For example, to calculate the value of
we write
int(x, 4, 9)
ans = 65/2
10/9/15 03:16:31 PM
MATLAB PRESENTATION
38
Dsolve command:
MATLAB provides thedsolvecommand for solving
differential equations symbolically. The most basic form of
thedsolvecommand for finding the solution to a single
equation is :
second order differential equation as: y" - y = 0, y(0) = -1, y'(0) =
2.
MATLAB Code :
dsolve('D2y - y = 0','y(0) = -1','Dy(0)
= 2')
ans = exp(t)/2 - (3*exp(-t))/2
10/9/15 03:16:31 PM
MATLAB PRESENTATION
39
Polynomial Algebra (Convolution Operator)
Polynomial products and factoring:
( x 2 3 x 2)( x 3 5 x 2 4 x 4) x 5 8 x 4 21x 3 26 x 2 20 x 8
MATLAB code :
For onvolution
For Deconvolution
>> p1=[1,3,2];
>> p2=[1,5,4,4];
>> pc=conv(p1,p2)
pc =
1
8 21 26 20
8
10/9/15 03:16:31 PM
>> deconv(pc,p2)
ans =
1
3
2
>> deconv(pc,p1)
ans =
1
5
4
4
MATLAB PRESENTATION
40
Mathematics Example:
Polynomial Roots
Find the roots of the following system:
y 12 x 2 x 8
MATLAB code:
>> roots([12 -1 -8])
ans =
0.8592
-0.7759
10/9/15 03:16:31 PM
Finding the Maxima and Minima of a Curve
Example
Let us find the stationary points of the function f(x) = 2x 3+
3x2 12x + 17
syms x;
y = 2*x^3 + 3*x^2 - 12*x + 17;
% defining the function
ezplot(y)
Our aim is to find some local maxima and minima on the graph, so
let
us find the local maxima and minima for the interval [-2, 2] on the
graph
syms x;
y = 2*x^3 + 3*x^2 - 12*x + 17;
ezplot(y, [-2, 2])
Laplace and Inverse Laplace
Transforms
MATLAB Code
Answer
laplace(a)
1/s^2
laplace(t^2)
2/s^3
ilaplace(1/s^3)
t^2/2
Fourier Transforms and Inverse Fourier Transforms
MATLAB Code
Answer
f = exp(-2*x^2);
FT = fourier(f)
FT = (2^(1/2)*pi^(1/2)*exp(w^2/8))/2
f = ifourier(-2*exp(abs(w)))
f =-2/(pi*(x^2 + 1))
Transfer function representation Using
Matlab
S 3 2 X 2 X 6 .3
f
X 2 0.05 X 3.14
MatLab
>>num = [1 -2 1 -6.3];
>>den = [1 0.05 -3.14];
>>f = tf(num,den)
Example
Examples
10/9/15 03:16:31 PM
MATLAB PRESENTATION
49
10/9/15 03:16:31 PM
MATLAB PRESENTATION
50
10/9/15 03:16:31 PM
MATLAB PRESENTATION
51
10/9/15 03:16:31 PM
MATLAB PRESENTATION
52
Matlab Programming for Engineers
Introduction to Matlab
Matlab Basics
Vectors and Matrices
Loops
Plots
MATLAB examples
Matrix Index
The matrix indices begin from 1 (not 0 (as in C))
The matrix indices must be positive integer
Given:
A(-2), A(0)
Error: ??? Subscript indices must either be real positive integers or
logicals.
A(4,2)
Error: ??? Index exceeds matrix dimensions.
10/9/15 03:16:31 PM
MATLAB PRESENTATION
54
Vectors and Matrices
Vectors (arrays) are defined as
>> v = [1, 2, 4, 5]
>> w = [1; 2; 4; 5]
>> A = [1,2,3;4,-5,6;5,-6,7]
10/9/15 03:16:31 PM
MATLAB PRESENTATION
55
Vectors and Matrices
How do we assign values to matrices ?
>>>A=[123;456;789]
A=
123
456
789
>>>
Columns separated by
space or a comma
10/9/15 03:16:31 PM
1 2 3
4 5 6
7 8 9
Rows separated by
semi-colon
MATLAB PRESENTATION
56
Vectors and Matrices
How do we access elements in a matrix or a vector?
>>>A(2,3)
ans=
6
>>>A(:,3)
ans=
3
6
9
>>>A(1,:)
ans=
123
10/9/15 03:16:31 PM
>>>A(2,:)
ans=
456
MATLAB PRESENTATION
57
Vectors and Matrices
Arithmetic operations Matrices
Performing operations to every entry in a matrix
>>>A=[123;456;78
9]
A=
123
456
789
>>>
Add and subtract
>>>A+3
ans=
456
789
101112
>>>A2
ans=
101
234
567
10/9/15 03:16:31 PM
MATLAB PRESENTATION
58
Vectors and Matrices
Arithmetic operations Matrices
Performing operations to every entry in a matrix
>>>A=[123;456;789]
A=
123
456
789
>>>
Multiply and divide
>>>A*2
ans=
246
81012
141618
>>>A/3
ans=
0.33330.66671.0000
1.33331.66672.0000
2.33332.66673.0000
10/9/15 03:16:31 PM
MATLAB PRESENTATION
59
Vectors and Matrices
Arithmetic operations Matrices
Performing operations to every entry in a matrix
Power
>>> A=[1 2 3;4 5 6;7 8 9]
A=
1
4
7
>>>
2
5
8
3
6
9
A^2 = A * A
10/9/15 03:16:31 PM
To square every element in A, use the
elementwise operator .^
>>>A.^2
ans=
149
162536
496481
>>>A^2
ans=
303642
668196
102126150
MATLAB PRESENTATION
60
Vectors and Matrices
Arithmetic operations Matrices
Performing operations between matrices
>>>A=[123;456;789]
A=
123
456
789
A*B
A.*B
10/9/15 03:16:31 PM
>>>B=[111;222;333]
B=
111
222
333
14 14 14
32 32 32
50 50 50
1x1 2 x1 3 x1
4 x 2 5 x 2 6 x 2
7 x3 8 x3 9 x3
MATLAB PRESENTATION
1
8
10 12
21 24 27
61
Vectors and Matrices
A./B
A.^B
10/9/15 03:16:31 PM
1/ 1 2 / 1 3 / 1
4 / 2 5 / 2 6 / 2
7 / 3 8 / 3 9 / 3
11 21
2
2
4
5
7 3 83
31
62
93
MATLAB PRESENTATION
1.0000 2.0000 3.0000
= 2.0000 2.5000 3.0000
2.3333 2.6667 3.0000
2
3
1
16
25
36
343 512 729
62
Tril/triu commands
>> a=[1 2
a=
1
2
4
5
7
8
3;4 5 6;7 8 9]
3
6
9
>> tril(a)
ans =
1
0
4
5
7
8
>> triu(a)
ans =
1
0
0
2
5
0
0
0
9
3
6
9
To extracts a sub matrix such that it
contains all the elements
corresponding to row number and
column number
2
3
1
A 4
5
6
7
8
9
D A(1 : 2,1 : 2)
1
D
4
10/9/15 03:16:31 PM
MATLAB PRESENTATION
64
Long Array, Matrix
t =1:10
t =
2
3
4
k =2:-0.5:-1
10
k =
1.5
0.5
-0.5
-1
= [1:4; 5:8]
x =
1
5
10/9/15 03:16:31 PM
2
6
3
7
4
8
MATLAB PRESENTATION
65
Generating Vectors from
functions
zeros(M,N)MxN matrix
of zeros
x = zeros(1,3)
x =
0
ones(M,N) MxN matrix of ones
rand(M,N) MxN matrix of uniformly
distributed random
numbers on (0,1)
10/9/15 03:16:31 PM
x = ones(1,3)
x =
1
1
1
x = rand(1,3)
x =
0.9501 0.2311 0.6068
MATLAB PRESENTATION
66
Concatenation of Matrices
x = [1 2], y = [4 5], z=[ 0 0]
A = [ x y]
1
B = [x ; y]
1 2
4 5
C = [x y ;z]
Error:
??? Error using ==> vertcat CAT arguments dimensions are not consistent.
10/9/15 03:16:31 PM
MATLAB PRESENTATION
67
Indexing Matrices
Indexing using parentheses
>> A(2,3)
Index submatrices using vectors
of row and column indices
>> A([2 3],[1 2])
Ordering of indices is important!
>> B=A([3 2],[2 1])
>> B=[A(3,2),A(3,1);
A(2,2);A(2,1)]
10/9/15 03:16:32 PM
MATLAB PRESENTATION
68
Indexing Matrices(Cond)
Index complete row or column using
the colon operator
>> A(1,:)
Can also add limit index range
>> A(1:2,:)
>> A([1 2],:)
General notation for colon operator
>> v=1:5
>> w=1:2:5
10/9/15 03:16:32 PM
MATLAB PRESENTATION
69
Matrix Concatenation Functions
The following functions combine existing matrices to form a new
matrix.
Function
Description
cat
Concatenate matrices along the specified dimension.
horzcat
Horizontally concatenate matrices.
vertcat
Vertically concatenate matrices.
repmat
Create a new matrix by replicating and tiling existing matrices.
blkdiag
Create a block diagonal matrix from existing matrices
This example constructs a new matrix C by concatenating matrices A
and B in a vertical direction
Example :
>>A = ones(2, 5) * 6; % 2-by-5 matrix of
6's
>>B = rand(3, 5);
% 3-by-5 matrix of
random values
>>C = [A; B]
concatenate A and B
% Vertically
Output :
C=
6.0000
6.0000
0.9501
0.2311
0.6068
6.0000
6.0000
0.4860
0.8913
0.7621
6.0000
6.0000
0.4565
0.0185
0.8214
6.0000
6.0000
0.4447
0.6154
0.7919
6.0000
6.0000
0.9218
0.7382
0.1763
Example :
a=
1
4
7
2
5
8
3
6
9
>> b=repmat(a,2,3)
b=
1
4
7
1
4
7
2
5
8
2
5
8
3
6
9
3
6
9
1
4
7
1
4
7
2
5
8
2
5
8
3
6
9
3
6
9
1
4
7
1
4
7
2
5
8
2
5
8
3
6
9
3
6
9
Creating a Block
Diagonal Matrix
The blkdiag function combines matrices in a diagonal direction and all
other elements of the matrix are set to zero
>>A = magic(3);
>>B = [-5 -6 -9; -4 -4 -2];
>>C = eye(2) * 8;
>>D = blkdiag(A, B, C)
Output:
D=
8 1
3 5
4 9
0 0
0 0
0 0
0 0
6
7
2
0
0
0
0
0
0
0
-5
-4
0
0
0
0
0
-6
-4
0
0
0
0
0
-9
-2
0
0
0
0
0
0
0
8
0
0
0
0
0
0
0
8
Example
10/9/15 03:16:32 PM
MATLAB PRESENTATION
76
10/9/15 03:16:32 PM
MATLAB PRESENTATION
77
10/9/15 03:16:32 PM
MATLAB PRESENTATION
78
10/9/15 03:16:32 PM
MATLAB PRESENTATION
79
10/9/15 03:16:32 PM
MATLAB PRESENTATION
80
Diagonal elements
10/9/15 03:16:32 PM
MATLAB PRESENTATION
81
fprintf ,Disp commands
Disp(x)
Disp(string)
disp(x) displays the array
If X is a string, the text is displayed
Ex :
z=2+3i;
fprintf('z= ');
disp(z)
Output :
Z= 2+3i
10/9/15 03:16:32 PM
MATLAB PRESENTATION
82
The fscanf and fprintf commands behave like C scanf and printf functions. They support the following
format codes:
Format Code
Purpose
%s
Format as a string.
%d
Format as an integer.
%f
Format as a floating point value.
%e
Format as a floating point value in scientific notation.
%g
Format in the most compact form: %f or %e.
\n
Insert a new line in the output string.
\t
Insert a tab in the output string.
10/9/15 03:16:32 PM
MATLAB PRESENTATION
83
Fprintf examples :
>> n=2;
>> fprintf('value is %d\n',n)
Output:
value is 2
fprintf('I have %d brother and %d
sister\n',1,1)
Output :
I have 1 brother and 1 sister
>> fprintf(This is %s department , we got %d years of NBA
accrediation/n','EEE',5)
Output : This is EEE department ,we got 5 years of NBA
accrediation/n>>
input command
Example :
x=input('enter the value of x');
y=input('enter the value of y');
z=x+y;
fprintf('the value of z is %d\n',z)
Output:
enter the value of x30
enter the value of y0
the value of z is 30
Input
Write the program to display 6th table
6*1=6
6*2=12
6*3=18
6*4=24
6*5=30
6*6=36
6*7=42
6*8=48
6*9=54
6*10=60
n=input('enter n value');
for i=1:10
fprintf('%d*%d=%d\n',n,i,n*i)
end
Importing data files into MATLAB
1.First create text file with name data
2.In matlab file ,
load data.txt