Introduction To Matlab Prepared by : 1 Prepared by: Eng. Amr Ezz Eldin Rashed Assistant lecturer TAIF university,KSA TEL:ksa 0554404723
Jul 16, 2015
Introduction To Matlab
Prepared by :
1
Prepared by:
Eng. Amr Ezz Eldin Rashed Assistant lecturer
TAIF university,KSA
TEL:ksa 0554404723
Outlines(First Level) _24 hour
What is Matlab
Basic commands
Vectors and matrices
Statistics for vector and matrix
Control loops(if,for,switch,break)
2D plotting , mathematics(int ,diff ,limit,..)
Exam 2
Outlines(Second Level)_24hour
3D plotting, animation
Dialog box
Simulink
Graphical user interface
Image and sound processing
البرامج الجاهزة
Project
EXAM 3
Outlines(Third Level)_24 hour
Introduction to Image Processing
Point Processing ,Spatial Filtering
Neighborhood Processing
The Fourier Transform
Image Restoration
Image Segmentation
project 4
What is Matlab?
What is possible in Matlab? graphic examples
How Matlab works? matrix, vector & scalar
syntax & important operators
basic commands & plot commands
creating a m-file
Statistics in Matlab some basics & example
Algebraic operations in Matlab
Useful links & other tutorials
5
Introduction to MATLAB
What is MATLAB
The name MATLAB stands for Matrix laboratory(or
mathematical laboratory).
MATLAB is an interactive system whose basic data element
is an array that does not require dimensioning.
It‟s both a computer programming language, and a software
environment for using that language effectively.
Typical
6
What is MATLAB
Matlab is a commercial "Matrix Laboratory" package which operates as an
interactive programming environment.
Matlab is available for PC's, Macintosh and UNIX systems.
Matlab is well adapted to numerical experiments.
Matlab program and script files (m-files) always have filenames ending with
".m";
The programming language is exceptionally straightforward since almost every
data object is assumed to be an array.
Graphical output (figure) is available to supplement numerical results.
Online help is available from the Matlab prompt (a double arrow) by typing help
7
Typical Uses
Math and computation
Algorithm development
Modeling, simulation, and prototyping
Data analysis, exploration, and
visualization
Scientific and engineering graphics
Application development including GUI
8
Why use Matlab?
Advantages:
Handles vector and matrices very nice
Quick plotting and analysis
EXTENSIVE documentation (type „help‟)
Lots of nice functions: FFT, fuzzy logic, neural nets,
numerical integration, OpenGL (!?)
Drawbacks:
Slow compared to C or Java
9
Matlab History
In the 1970‟s, Cleve Moler “Professor of Math & Computer
Science, Chief Author of MatLab and one of the Founders of
Mathworks.Inc” participated in developing (EISPACK) and
(LINPACK). Those were collection of Fortran subroutines for
solving linear equations and Eigen value problems.
Later, when teaching courses in mathematics, Moler wanted
his students to be able to use LINPACK and EISPACK
without requiring knowledge of Fortran, so he developed the
first MATLAB in 1977 as an interactive system to access
LINPACK and EISPACK.
10
MatLab History
The first Matlab was written in 2000 lines of Fortran, with Matrices as the only data type, 80 functions, no .m files and no toolboxes.
Jack Little, one of Moler‟s students saw Matlab potentials in Control systems & Signal Processing. They founded together Mathworks, Inc. in 1980
Mathworks is now responsible for development, sale, and support for MATLAB
MATLAB was rewritten in C with more functionality (such as plotting
routines), and now it contains more than 80,000 functions.
11
The Basic Matlab System
It consists of 5 main parts:
– Development Environment.
– MATLAB Mathematical Function Library.
– MATLAB Language.
– Graphics.
– MATLAB External Interfaces
And finally the MatLab Toolboxes
– Toolboxes are comprehensive collections of MATLAB functions (M-
files) that extend the MATLAB environment to solve particular classes
of problems.
– Areas in which toolboxes are available include signal processing,
control systems, neural networks, communications, wavelets, Data
Acquisition, simulation, and many others.
12
MATLAB Development
Environment & Basic Math
Functions
13
Development Environment
• Run the matlab
14
Development Environment
15
Command Window
History
Work Space
Variables
stores here
All of ur previous
commands
stores here
All commands,
programs runs from
here
Variables
MATLAB variable names must begin with a
letter, which may be followed by any combination
of letters, digits, and underscores. MATLAB
distinguishes between uppercase and lowercase
characters, so A and a are not the same
variable(case sensitive).
When naming a variable, make sure you are not
using a name that is already used as a function
name,begin with character .
Special Values
Function description
Ans Most recent answer (variable). If you do not assign an output variable to an
expression, MATLAB automatically stores the result in ans.
pi 3.1415926535897...
inf Infinity. Calculations like n/0, where n is any nonzero real value, result in
inf.
I,J The imaginary unit √-1
NaN,nan Not-a-Number, an invalid numeric value. Expressions like 0/0 and inf/inf
result in a NaN, as do arithmetic operations involving a NaN. n/0, where n
is complex, also returns NaN.
Special Values
Description Function
Beep sound beep
Maximum real number that can be used realmax
minimum real number that can be used
realmin
Specifies the accuracy of floating point
Precision .
الخطوة بن عددن أو أصغر عدد مكن تعرفه
eps
18
Operators
Arithmetic
– numeric computations, e.g., 2^10
Relational
– quantitative comparison of operands
– e.g., a < b
Logical
– AND, OR, NOT
–return Boolean variable, 1 (TRUE) or 0 (FALSE)
Arithmetic operators
example symbol Operation
3+22 + Addition
54.6-16.5 _ subtraction
3.14*6 * Multiplication
10/100
100\10 / or \ Division
2^8 ^ power
20
Relational Operators
Description
Relational Operator
Less than
<
Less than or equal
<=
Greater than
>
Greater than or equal
>=
Equal to
==
Not equal to
~=
21
Examples
Command Result
5>8 ans=0
A=5<10 A=1
Y=(6<10)+(7>8)+(5*3==60/4) Y=2
B=[15 6 9]; C=[8 20 9];
D=C>=B
D=[0 1 1]
B= =C ans=[0 0 1]
B>6 ans=[1 0 1]
Logical Operators
Logical Operator Description
& Element by element AND
| Element by element OR
~ NOT
&& Scalar AND with short circuiting
|| Scalar OR with short circuiting
Examples
Command Output
3 & 7 ans=1
A=5 | 0 A=1
~25 ans=0
(12 & 0) +(~0)+(0 | 5) ans=2
X=[9 3 0]; Y=[2 0 13] X & Y ans=1 0 0
Z=X | Y Z=1 1 1
Operator Precedence
Precedence Operation
1 (highest) ( )
2 ^
3 ~
4 *, /
5 +, -
6 Relational operations >,<, …
7 &
8 |
Complex functions Description Item
Define a complex number Complex(2,-3)
Absolute value ;|x| Abs(x)
Angle of complex number x Angle(x)
Complex conjugate of x Conj(x)
Imaginary part of a complex number x Imag(x)
Real part of complex number x Real(x)
26
Example
27
Relational and Logical Functions
Function Description
xor(x,y) Exclusive OR
any(x) True if any element is non zero
all(x) True if all elements are non zero
Isequal(x,y) True if arrays are numerically equal
Isfloatpt True for a floating point number
isprime True for a prime number
Example
29
Information About System
30
Information About System
31
Calendar
32
Information About System
33
System and file commands Description Item
Clears command window clc
Remove variables from memory Clear , clear all
Display documentation doc
Checks for existence of file or variable exist
Declares variables to be global global
Display help text in the command window Help
Display help text in the help browser
helpwin
Searches help entries for a keyword lookfor
Stops Matlab Quit or exit
List current variables who
Long display) )List current variables whos 34
How to open file (mspaint.exe)
35
Trigonometric functions(Radian)
Description Item
Inverse cosine Acos(x)
Inverse cotangent Acot(x)
Inverse cosecant Acsc(x)
Inverse secant Asec(x)
Inverse sine Asin(x)
Inverse tangent Atan(x)
Cosine Cos(x)
cotangent Cot(x)
cosecant Csc(x)
Sine Sin(x)
tangent Tan(x)
36
Trigonometric functions(degree)
Description Item
Inverse cosine Acosd(x)
Inverse cotangent Acotd(x)
Inverse cosecant Acscd(x)
Inverse secant Asecd(x)
Inverse sine Asind(x)
Inverse tangent Atand(x)
Cosine Cosd(x)
cotangent Cotd(x)
cosecant Cscd(x)
Sine Sind(x)
tangent Tand(x)
37
Hyperbolic function
Description Item
Inverse cosine Acosh(x)
Inverse cotangent Acoth(x)
Inverse cosecant Acsch(x)
Inverse secant Asech(x)
Inverse sine Asinh(x)
Inverse tangent Atanh(x)
Cosine Cosh(x)
cotangent Coth(x)
cosecant Csch(x)
Sine Sinh(x)
tangent Tanh(x)
38
Mathematical functions item Description
factor التحلل ال العوامل االولة
Primes االولة االقل من ولد قائمة باالعدادx
isprime عدtrue اذا كان العدد اولا
Gcd المشترك االكبر القاسم
lcm المضاعف المشترك االصغر اجاد
Factorial(x) الجاد المضروب
Gamma(x) تابع جاما
Beta(x,y) بتا تابع 39
Examples
40
Example
41
System and file Commands
item Description
cd Change current directory
Date Display current date
dir Lists all files in the current directory
mkdir Used to make new directory
pwd Present work directory
what Lists all matlab files
Clock Display current clock and date 42
Example
43
Exponential functions item Description
exp التابع االس
log اللوغارتم الطبع
log10 10اللوغارتم لالساس
log2 2اللوغارتم لالساس
Sqrt(x) الجذر التربع
nthroot الجذر من المرتبةn
pow2 2^(x)
expm1 Exp(x)-1
log1p Log(x+1)
44
Example
45
Example
46
Erf,erfc,expint,format
47
تابع اجاد الخطأ
تابع اجاد الخطأ المتمم
اجاد التكامل االس
رقم بفاصلة عائمة 15
format
48
ارقام بفاصلة ثابتة 5
ارقام بفاصلة عائمة 5
رقم بفاصلة عائمة 15
الشكل الكسري
الرياضيات في الماتالب
الجاد جذور المعادلة
X^4+2*x^3+4*x+5=0
>>roots([1 2 0 4 5])
والجاد المعادلة بمعرفة الحلول
>>poly([1 2 3 4])
49
Cont.
50
Integration
51
Differentiation
52
Laplace Transform
53
Expand ,conv ,and deconv
54
limit
55
Vector defenition
56
Vector definition
57
Array addressing
58
Array addressing
59
Adding element to vector
60
Vector statistics
61
Max ,min ,
Cont.
63
Linspace , logspace
64
Array Construction
65
Array Construction
66
Array orientation
>> c=[1;2;3;4;5]
c =
1
2
3
4
5
>> c‟ % transpose of c
ans =
1 2 3 4 5
Array orientation
>> s=[1+2i 3-5i 3+4i]
s =
1.0000 + 2.0000i 3.0000 - 5.0000i 3.0000 + 4.0000i
>> f=s‘
f =
1.0000 - 2.0000i
3.0000 + 5.0000i
3.0000 - 4.0000i
>> g=s.‘ dot transpose operator g =
1.0000 + 2.0000i
3.0000 - 5.0000i
3.0000 + 4.0000i
Matrix definition
69
Math.
70
Cont.
71
Mean and Variance
Determine,diagonal,inverse
73
Maximum,minimum
74
Find location of an element
75
برنامج لحساب زاوة خط
X=[1 0 0;0 1 0;0 0 1];
[I,j]=find(x==1);
Length=max(i)-min(i);
Width=max(j)-min(j);
Ang=atand(length/width);
76
Determines matrix elements
d=[ 1 2;4 5; 3 2]
d =
1 2
4 5
3 2
>> d(1,:) %row 1 and all columns
ans =
1 2
>> d(1,2) % row 1 and all column 2
ans =
2
>> d(:,2) %all row and l column 2
ans =
2
5
2
Determines matrix elements
d =
1 2
4 5
3 2
>> d(2:3,:) ans =
4 5
3 2
Add element to matrix
79
Add element to matrix
80
Special Matrix(zeros,ones,magic,eye)
>> f=zeros(3) zeros=false
f =
0 0 0
0 0 0
0 0 0
>> g=ones(4) ones=true
g =
1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1
Special Matrix
>> v=zeros(2,3)
v =
0 0 0
0 0 0
>> h=3*ones(2,4)
h =
3 3 3 3
3 3 3 3
Special Matrix
>> eye(3,3)
ans =
1 0 0
0 1 0
0 0 1
True ,false
84
Special matrix(rand,randn,randint)
85
Zero mean
unit variance
Random number
between 0 and 1
Mean2,std2,randint
86
Unique,intersect,setdiff
87
لحذف ما هو مكرر
وترتب النتجة
الحصول عل العناصر
المشتركة بن مصفوفتن
الحصول عل العناصر
وغر 1الموجودة ف
2موجودة ف
Rot90,flipud,fliplr
Matrix operations
89
Example
90
Example
91
Example
92
Example
93
Example
94
Example
95
Add element to matrix
96
Add element to matrix
97
Add element to matrix
98
Reshape,repmat
99
Approximation functions
Floor : rounds value towards negative
infinity
Ceil: rounds value towards positive infinity
Fix: rounds value towards zero
Round: normal approximation
100
Approximation functions
101
Approximation functions
102
Approximation functions
103
Number systems
104
Cont.
105
Character matrix
106
Character matrix
107
Character matrix
108
Tic,toc
109
Multidimensional matrix
110
Cont.
111
Cont.
112
Cont.
113
Introduction to signal and image processing
114
Reading image
>> x=imread('C:\Program
Files\MATLAB\R2007a\toolbox\images\imd
emos\cameraman.tif');
>>y=imread('cameraman.tif');
>> imshow(y)
115
Image show
116
Operations on image
117
Operations on image
>> diag(y);
>> trace(y)
ans =
27029
>> imshow(flipud(y))
>>imresize(y,[128 128]);
118
Figure(2)
119
120
>>imshow(fliplr(y));
Edge detection
121
Cont.
122
Cont.
123
Color image,imwrite
124
imwrite
imwrite(z,'amr.jpg')
imwrite(y,„d:\amr2.jpg')
125
Reading and writing sound
>>[y,fs]=wavread('C:\WINDOWS\Media\chi
mes.wav');
>>Help auread
>> soundsc(y) or wavplay(y,fs)
>>size(y)
>>wavwrite(y,‟c:\aa.wav‟) or auwrite
نأخذ جزء من الصوت ونتعامل معه<<
126
Operation on sound
127
Video read
128
Cont.
129
Flow Control
MATLAB has several flow control constructs:
For loop.
If statement.
Switch and case.
While.
Continue.
Break.
Try – catch.
Return.
For Loop
for x = array
(commands)
end
The (commands) are executed once for
every column in array
At each iteration, x is assigned to the next
column of the array
Example
For i=1:10
i
end
i≤10 نفذ طالما
132
Example
for i=1:10
disp(i)
end
بجانب كل قمةI ال عرض كلمة
133
Example♣♣
disp(„the numbers from 1 to 10 are:‟)
for i=1:10
disp(i)
end
134
Factorial
n=5;
f=1;
for i=2: n
f=f*i;
end
disp(f)
135
1:5إلجاد مجموع األعداد من ◄
n=5
s=0
for i=1: n
s=s+i;
end
disp(s)
136
1:5إلجاد مجموع مربعات األعداد من ◄
n=5
s=0
for i=1: n
s=s+i^2;
end
disp(s)
137
1:5إلجاد جذور األعداد من ◄
n=5;
for i=1: n
disp(sqrt(i))
end
138
Example
n=5
disp(„number square root‟)
disp(„ „)
for i=1: n
AA=sqrt(I);
disp([ I AA ])
لعرض مجموعة من المتغرات
End
139
Example
N=10
12/1! + 22/2!+………..+n2/n!
اإلشارة ثابتة
12/1! -22/2!+…-……..+n2/n!
اإلشارة متغرة
140
Example
n=5;
fact=1;
Sum=0;
For I=1:n
fact=fact*I;
T=(I^2)/fact;
sum=sum+ T;
End
Disp(sum) 141
Example
ملحوظة◄
لعمل إشارة أحد الحدود موجب واآلخر سالب
(-1) i+1
Fact=-1
Fact= - fact *i
142
Example
n=input („enter any integer‟);
Sum =0;
For i=1: n
Sum=sum+i
End
Disp(sum);
143
Example
What is your name?
How old are you?
age, nameطبع
144
Example
Nam=input („what is your name?‟ , ‟s‟);
character حتوي علىstring
Age=input („how old are you?‟);
Disp(nam)
Disp(age)
145
Note
:ملحوظة
\لك ترك سطر نستخدم عالمة
\\نستخدم عالمة backslashولك طبع
بجانب بعضهم name ,ageولطبع
Disp ([x, y]);
x, yإما أن كون ⤾
String or numأي جب أن كونا من نفس النوع
Disp ([nam, num2str (age)]);
146
Example
5اطبع مجموع األعداد التى تقبل القسمة على
sum=0;
For i=0:5:100
sum=sum+I;
end
Disp(sum)
147
Nested Loops
for n=1:5
for m=5:-1:1
A(n,m)=n^2+m^2;
end
end
A =
2 5 10 17 26
5 8 13 20 29
10 13 18 25 34
17 20 25 32 41
26 29 34 41 50
3x3 Mean filter
149
While Loops
while expression
(commands)
end
Commands are executed as long as all elements in expression are true.
Usually evaluation of expression gives scalar
–In case of array all elements must be true
Example
while x<=15
x=2*x;
end
Be careful and try to avoid infinite loops!
To stop the execution of an infinite loop use Ctrl+C
x =3
x =24
If-End Structure
if expression
(commands)
end
The (commands) are evaluated if all
elements in expression are true (nonzero)
If-Else-End Structure
if (expression)
(commands evaluated if true)
else
(commands evaluated if false)
end
Flow control - selection
The if-elseif-else construction
if <logical expression>
<commands>
elseif <logical expression>
<commands>
else
<commands>
end
if height>170
disp(’tall’)
elseif height<150
disp(’small’)
else
disp(’average’)
end
Example
X=input ('enter any value');
If (x>0) disp ('positive');
End
IF (x<0) disp ('negative');
End
endب matlab ال غلق برنامج ال
155
Example
iF (x>0) disp ('positive');
else if (x<0) disp ('negative');
else
disp ('zero');
End
وجد دالة جاهزة تقوم بنفس الوظفة:ملحوظة
sign
156
Example
x,yأدخل قمة
x,yام ال ونطبع yاكبر من x ونحدد هل
X is greater than y
X is lower than y
X is equal to y
157
Example
158
Example
5لطباعة األعداد التى ال تقبل القسمة على
For i=0:100
If (rem(I,5)~=0)
disp(i);
End
End
159
برنامج الجاد جذور معادلة تربعة
Disp.→this program is used to solve the quadratic eqn
Disp→ Ax2+Bx+c=0
a=input→enter the value of A:___
b=input→enter the value of B:___
c=input→ enter the value of C:___
D=B2- 4AC
• X1=x2=-b/2a X1= (-B+sqrt (d))/ (2*a))
X2= (-B-sqrt (d) )/ (2*a))
160
0 Non zero
Program
161
Example
X=floor (rand*6) +1;
If (x==1) disp ('that is 1');
Else if (x==2) disp ('that is 2');
Else if (x==3) disp ('that is 3');
Else if (x==4) disp ('that is 4');
Else if (x==5) disp ('that is 5');
Else disp ('that is 6');
Or else if (x==6) disp ('that is 6'); end
162
برنامج درجات الطالب
163
Example
apples=10;
cost=apples*25;
if apples > 5
cost=(1 -20/100)*cost % 20% discount
end
Switch-Case Construction
switch expression
case test_expression1
(commands1)
case {test_expression2, test_expression3}
(commands2)
otherwise
(commands 3)
end
Example
method = 'Bilinear'; switch (method) case 'linear' disp('Method is linear') case 'cubic' disp('Method is cubic') otherwise disp('Unknown method.') end Method is Unknown method
multiple casesفى حالة switchباستخدام
X=floor (rand*6)+1;
Switch x → expression or variable مكن أن كون
Case 1
Disp ('that is 1');
Case 2
Disp ('that is 2');
Case 3
Disp ('that is 3');
Case 4
Disp ('that is 4');
Case 5
Disp ('that is 5');
Case 6
Disp ('that is 6');
Or
Otherwise
Disp ('that is 6'); End
167
Program
168
Example
لحساب أكثر من حالة مع بعض
X=floor (rand*6)+1;
1-if (x==1 | x==2 | x==3)
2-if (1<=x<=3)
3-case {1,2,3}
disp ('from 1 to 3')
case {4,5}
disp ('4 or 5')
case 6 / otherwise
disp (that is 6');
end
169
Program
170
Program
171
passwordبرنامج لعمل
172
Another solution
173
Another solution
174
program
ف 3المطلوب ف البرنامج السابق جعل عدد المحاوالت
.حالة كلمة السر الخطأ وواحدة ف حالة الكلمة الصححة
175
program
176
while
177
Fprintf,save,load,uisave
178
لحساب الوقت المستغرق لتنفذ برنامج
179
program
Enter the no. of student=n
Vector (x)
Average = mean (x)
The first = max (x) الطالب األول
The last = min (x) الطالب األخر
180
program
181
Example
A=[2 3;0 4];
B=[-5 7;10 2];
Display
1-add a to b
2-max value of a
3-Diag of b
4-exit
182
program
183
program
184
Another solution
185
الدخال عناصر مصفوفة
Enter the number of raws
Enter the number of column
Enter the values
186
program
187
Security program
0 5 0 1
2 3 4 6
0 10 15 20
1 8 0 2
3 5 0 1
2 3 4 6
188
program
189
Matlab simulink
190
simulink
191
simulink
192
Example
193
simulink
194
Cont.
195
196
197
Example 2
198
Cont.
199
Cont.
200
Cont.
201
Cont.
202
Cont.
203
Cont.
204
Cont.
205
Simulink Power Window Controller Hybrid System Model
206
Filtered QPSK vs. MSK
207
Cont.
208
AM DSB_SC modulation
209
Scope
210
Image processing example
211
o/p video viewer
212
Simple power model
213
Cont.
214
Scop
215
Simple models(simpower system)
216
Power electronic models(simpower sys)
217
Graphical User Interface
218
Start Guide
219
Example
220
Property Inspector
221
Figure
222
Call backs
223
Call Backs
224
Project 2
225
Example 2
226
Example
227
Open file
228
Pop up menu
229
Edit button
230
Push button
231
Program 3
232
Am modulation
233
Operation
234
Pop up menu
235
Carr_freq
236
Sampling_freq
237
Am_mod
238
Import data
239
Code
% --- Executes on button press in put.
function put_Callback(hObject, eventdata, handles)
% hObject handle to put (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
% handles structure with handles and user data (see
GUIDATA)
distor=200;
set(handles.edit1,'String',distor);
240
Calculator program
241
Calculator program2
242
243
244
حل المعادلة التربعة
245
Menu editor
246
برنامج عرض صورة الوان وابض واسود
247
برنامج كلمة المرور
248
Visible property
249
Code
250
Open , save (menu items)
251
البرامج الجاهزة
252
Funtool
253
تحدد مركز الهزة االرضة
254
رسم اشارة وتصمم المرشح المرغوب به
255
Analog modulation
256
RLC demo
257
Neural network tool
258
nftool
259
nprtool
260
Wavelet transform
261
sigdemo1
262
Filter design tool
263
xpsound
264
querybuilder
265
Gui to exe))deploytool
266
phone
267
nndtoc
268
nctool
269
Dialog box
270
helpdlg
271
Input dialoge
272
Message box
273
Color question
274
Warning dialog
275
Wait bar
276
List dialog
d = dir;
str = {d.name};
[s,v] = listdlg('PromptString','Select a file:',...
'SelectionMode','single',...'ListString',str)
277
List dialog
smpl_length={'20','25','30','100','200','500'};
entry2=listdlg('name','input for sample
lengths','promptstring',...
'enter sample length
values','liststring',smpl_length);
278
Cont.
279
Uigetfile
280
uisave
281
uiopen('figure')
282
[file,path] = uiputfile('animinit.m','Save file name');
283
Graphics
284
Sine wave
285
0 1 2 3 4 5 6 7-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Program 2
286
Figure
287
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
4
5
6
Program 3
288
figure
289
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
4
5
6aaaaaaa
time
dist
ance
Program 4
290
figure
291
0 0.5 1 1.5 2 2.5 3 3.5 40
1
2
3
4
5
6aaaaaaa
time
dist
ance
xxxx
move with mouse
Program 5
292
figure
293
1 2 3 4 5 6 7 8 9 100
100
200
300
400
500
600
700
800
Program 6
294
Figure
295
0 1 2 3 4 5 6 7-5
0
5
10
15
20
25
30
35
40
Program 6
296
الرسم بإستخدام االحداثات الدائرة
297
figure
298
0.1
0.2
0.3
0.4
0.5
30
210
60
240
90
270
120
300
150
330
180 0
Program 7
299
Program 8
300
Figuer
301
1 2 3 4 5 6 7 8 9 100
10
20
30
40
50
60
70
80
90
100
Program 9
302
figure
303
1 2 3 4 5 6 7 8 9 100
50
100
1 2 3 4 5 6 7 8 9 100
0.5
1
Program 10
304
Program 11
305
Program 12
306
Figure
307
0 2 4 6 8-1
-0.5
0
0.5
1
0 2 4 6 8-1
-0.5
0
0.5
1
0 2 4 6 8-1
-0.5
0
0.5
1
-5 0 5 10-1
-0.5
0
0.5
1
Program
308
Figure
309
0 2 4 6 8-1
-0.5
0
0.5
1number one
0 2 4 6 8-1
-0.5
0
0.5
1number two
0 2 4 6 8-1
-0.5
0
0.5
1number three
-5 0 5 10-1
-0.5
0
0.5
1number four
ezplot
310
-6 -4 -2 0 2 4 6
-1
-0.5
0
0.5
1
x
sin(x)
cont
311
-6 -4 -2 0 2 4 6
0
0.2
0.4
0.6
0.8
1
x
sin(x)2
312
-5 0 5
0
20
40
60
80
100
120
140
160
x
4 x2
-5 0 5
-50
-40
-30
-20
-10
0
10
20
30
40
50
x
8 x
-5 0 57
7.2
7.4
7.6
7.8
8
8.2
8.4
8.6
8.8
9
x
8
-5 0 5-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
x
0
Graphics 3d
313
Figure
314
00.2
0.40.6
0.81
00.2
0.40.6
0.810
0.2
0.4
0.6
0.8
1
x axisy axis
z label
program
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
surf(X,Y,Z)
315
figure
316
-2
-1
0
1
2
-2
-1
0
1
2-0.5
0
0.5
program
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
subplot(221)
mesh(Z)
subplot(222)
mesh(Z)
view(-37.5,70)
subplot(223)
mesh(Z)
view(-37.5,10)
subplot(224)
mesh(Z)
view(0,0)
317
figure
318
020
40
0
20
40-0.5
0
0.5
0
20
40
0
10
20
30-0.5
00.5
0 20 400
2040
-0.5
0
0.5
0 10 20 30-0.5
0
0.5
sphere
319
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1-1
-0.5
0
0.5
1
Sphere(40)
320
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1-1
-0.5
0
0.5
1
mesh
[x,y,z]=sphere(40);
Mesh(x,y,z)
321
Figure
322
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1-1
-0.5
0
0.5
1
cylinder
323
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
10
0.2
0.4
0.6
0.8
1
Cylinder(r,n)
324
-5
0
5
-5
0
50
0.2
0.4
0.6
0.8
1
program
[x,y,z]=cylinder(5,30);
Mesh(x,y,z)
325
figure
326
-5
0
5
-5
0
50
0.2
0.4
0.6
0.8
1
program
t = 0:pi/50:10*pi;
plot3(sin(t),cos(t),t,‟r‟);
Grid;axis square
327
figure
328
-1
-0.5
0
0.5
1
-1
-0.5
0
0.5
1
0
10
20
30
40
Pie,pie3
Subplot(211)
pie([1 2 3 5],{'North','South','East','West'})
Subplot(212)
pie3([2 4 3 5],[0 1 1 0],{'North','South','East','West'})
329
figure
330
North
South
East
West
East
West
South
North
program
331
figure
332
1 1.5 2 2.5 34
5
6
7
0 0.5 10
0.2
0.4
0.6
0.8
1
0 0.5 10
0.2
0.4
0.6
0.8
1
0 0.5 10
0.2
0.4
0.6
0.8
1
program
333
rectangle('Position',[0.59,0.35,3.75,1.37],...
'Curvature',[0.8,0.4 ],...
'LineWidth',2,'LineStyle','--')
figure
334
0.5 1 1.5 2 2.5 3 3.5 4 4.50.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
program
rectangle('Position',[0.59,0.35,3.75,1.37],...
'Curvature',[0 0],...
'LineWidth',2,'LineStyle','--')
335
figure
336
0.5 1 1.5 2 2.5 3 3.5 4 4.50.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
program
clf;close all;clear all;
rectangle('Position',[0.59,0.35,3.75,1.37],...
'Curvature',[1 1],...
'LineWidth',2,'LineStyle','--')
337
Figure
338
0.5 1 1.5 2 2.5 3 3.5 4 4.50.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
program
clf;close all;clear all;
rectangle('Position',[0.59,0.35,3.75,1.37],...
'Curvature',[1 1],...
'facecolor','g')
339
figure
340
0.5 1 1.5 2 2.5 3 3.5 4 4.50.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
program
341
Figure
342
02
46
810
0
5
100
2
4
6
8
10
program
343
Figure
344
020
40
0
20
40-0.5
0
0.5
0
20
40
0
10
20
30-0.5
00.5
0 20 400
2040
-0.5
0
0.5
0 10 20 30-0.5
0
0.5
program
345
Figure
346
05
1015
2025
0
10
20
30-30
-20
-10
0
10
20
30
Draw circles
347
Result
348
PROGRAM
المطلوب هو عمل برنامج لوضع االسم والدرجة والتقدر
كل واحدة ف مصفوفة وعرضهم
349
350
functions
Main program
for i=1:10
disp(i)
s(i)
end
Function s(i)
for k=1:i
fprintf(„*‟)
end
fprintf(„ „) 351