Introduction to Matlab Lecture 1: Getting Started - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Introduction to Matlab Lecture 1: Getting Started

Description:

Title: Introduction to Matlab Lecture 1: Getting Started Author: faviluki Last modified by: U.L.B. Created Date: 10/9/2007 1:10:08 PM Document presentation format – PowerPoint PPT presentation

Number of Views:101
Avg rating:3.0/5.0
Slides: 39
Provided by: fav47
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Matlab Lecture 1: Getting Started


1
??????S????? T?SS????S ????? ????????GO?
???????O? ??????????S
???G???????S??S ?/?
?. Sa????, sarris_at_uth.gr, t??. 2421074090
????e?? 11 ???s? d?µ??, e??te????? a??e??? ?a?
??af???? st? Matlab
?a???? e??µ??? 2008
2
??????s? t?? pa???s?as??
  • ??µ?? e??????
  • ???te???? a??e?a
  • G?af???
  • ???? µe t?? p?a?t??? e??s??s? a?t? p?? ?a de?te
    st?? t??? ?a sa? ?????? ??et??? µe t? Matlab!!!

3
??µ?? e??????
HI_LO plays the game with this name. When
prompted enter your guess, the computer will
tell you if your guess is above or below the
random number calculated by the computer. x
fix(100rand) n 7 test 1 for k 17
numb int2str(n) disp( 'You have right to
' numb ' guesses' ) disp( 'A guess is a
number between 0 and 100') guess
input('Enter your guess ') if guess lt x
disp('Low') elseif guess gt x
disp('High') else disp('You
won') test 0 break
end n n - 1 end if test gt 0 disp('You
lost') end
4
??µ?? e?????? se s??a?t?se??
PIPE plots the diagram of smooth-pipe friction
coefficients. This M-file calls function
SPIPE. See Example 7.4, Flow through
smooth pipes. reynolds logspace(2.5, 6.3,
100) coeff zeros(1,100) for k 1 1 100
re reynolds(k) co spipe(re)
coeff(k) co End loglog(reynolds,
coeff) grid title('Frictional coefficient of
smooth pipes') xlabel('Reynolds number,
Re') ylabel('Friction coefficient, \lambda')
5
??µ?? e?????? se s??a?t?se?? (s????e?a)
function lambda spipe(Re) SPIPE smooth-pipe
frictional coefficient. spipe(Re) is the
smooth-pipe frictional coefficient for
Reynolds numbers 0 lt Re lt 106. if Re lt 2320
lambda 64/Re elseif Re lt 105
lambda 0.3164/Re0.25 else if Re lt
3106 x0 -0.8 2log10(Re)
x -0.8 2log10(Re/x0)
while (abs(x - x0) gt 0.000001)
x0 x x
-0.8 2log10(Re/x0) end
lambda 1/(xx) else
disp('Reynolds number gt 106')
disp('Calculation aborted') end end
6
?a??de??µa s????t?s??
function y ustep(t, t0) USTEP(T, t0)
unit step at t0 See Section 7.2,
Conditional branching. m, n size(t) y
zeros(m, n) initialize y array of
points for k 1 length(t) if t(k) lt t0
y(k) 0 else
y(k) 1 end end
7
?pe??e? epa?a???e??
EXA07_02 Example 7.2, Infinite WHILE loop.
See Section 7.2. x 1 while x 0 x
x - 0.2 end
8
??µ?? e??????
function y fact(x) FACT factorial by a
recursive procedure. FACT(X) is the
factorial of X by a recursive procedure,
where X is an integer scalar. See Section 7.6,
Recursion. if sum(size(x)) 2
error('Argument is not a scalar, calculation
aborted') elseif x fix(x)
error('Argument is not an integer, calculation
aborted') else if x 0
y 1 else y
xfact(x-1) end end
9
???te???? a??e?a
  • ?µe??????? ?p?????sµ?? (log-file)
  • ?ed?µ??a ap? a??e?a m
  • ?p?st??f? st? ?e?t??????? s?st?µa
  • ????af? ded?µ???? se e??te???? a??e?a
  • ??ta??a?? ded?µ???? µe t? Excel
  • ?p?p??s?ete? e?t???? e?s?d??/e??s??

10
???te???? a??e?a (s????e?a)
?µe??????? ?p?????sµ?? (log-book) ??t???
diary S??ta?? diary filename on off ?
diary('filename') ?p????e?s? ?s??
eµfa?????ta? st? pa?????? e?t???? (e?t??
??af?µ?t??) ???s?µ? p??t? e?t???
date ???s? s?????? () ??a epe????se??
11
???te???? a??e?a (s????e?a)
?ed?µ??a se a??e?a t?p??-m ??ad??as?a
s????af?? ???s? t?? MATLAB Editor ??a??af?
t?? ded?µ???? ?? µetaß??t?? ?p????e?s? ??
a??e?? t?p?? m F??t?µa t?? µetaß??t?? µe ???s?
t?? a??e??? m p?? d?µ?????????e ?etat??p?
ap? ap?? text Data acquisition se µ??f? text
12
???te???? a??e?a (s????e?a)
?ed?µ??a se a??e?a t?p??-m ??d??? pe??pt?s?
p??a?e? a?af???? (lookup tables) ??a??a?t???
ap????e?s? se a??e?a t?p??-mat ??t??? save
13
??t??es? e?t???? t?? ?e?t????????
??t??es? e?t???? t?? ?e?t???????? s?st?µat?? (OS
shell) ???s? t?? s?µß???? ! !dir
!explorer !copy diary.txt mydiary.txt ?e
µ??f? s??a?t?se?? dos('e?t???'), unix('e?t???')
14
????af? ded?µ???? se a??e??
?a??de??µa d?µ??????a a???????a?
t??a??? a???µ?? ?a? ap????e?s? se a??e?? t?p??
text x1100 yrandn(1,100) fid fopen(
'file.dat', 'w') for i1100, fprintf(fid,
't3d\tv2.5f\n', x(i), y(i)) end fclose(
fid) fscanf(fid, format) fgets, fgetl, textread


a?????s? ded?µ????
15
????af? ded?µ???? se a??e?? (s????e?a)
?a??de??µa d?µ??????a a???????a?
t??a??? a???µ?? ?a? ap????e?s? se a??e?? t?p??
binary yrandn(1,100) fid fopen( 'file.bin',
'wb') fwrite(fid, y, 'float') fclose( fid)
fread( fid, size, precision) a?????s? ded?µ????
binary yyfread( fid, inf, 'fload')
16
??a???? ded?µ???? st? Excel
???p?? 1 µe ???s? t?? e?t????
diary xrand(10) diary excel.out x diary off
???p?? 2 µe ???s? t?? e?t???? fprintf xrand(10)
fidfopen('excel.out','wt') for fprintf
fclose(fid) ???p?? 3 µe ???s? t?? e?t????
xlswrite success, message xlswrite( file,
array,sheet, range) xrand(10) success,
message xlswrite( 'test.xls', x)
?????µa t?? Excel File/Open/All files/wizard
?????µa t?? Excel drag-drop excel.out
17
??sa???? ded?µ???? ap? t? Excel
???p?? 1 ??t??? xlsread n xlsread(
'spreadsheet' ) n xlsread( 'spreadsheet',
'sheet2' ) n xlsread( 'spreadsheet', 'sheet2',
'a2j5' ) n, t, r xlsread() n numeric,
t text, r raw n, t e??a? ?p?s????a t?? r
???p?? 2 ???s? t?? wizard st? menu FileImport
Data
18
S??a?t?se?? a??e???
?????µa ?a? ??e?s?µ? a??e??? fopen -
?????µa fclose - ??e?s?µ? ???sd????sµ?? ??s??
e?t?? t?? a??e??? feof - ??e???? ??a t????
a??e??? ferror - ?at?stas? sf??µat?? a??e???
frewind - epa?af??? st?? a??? fseek -
t?p???t?s? se s???e???µ??? ??s? ftell -
a?a?????s? t?????sa? ??s?? ??s?d??-???d??
µ??f?p???µ???? a??e??? fgetl - a?????s? µ?a?
??aµµ?? ????? ?a?a?t??a a??a??? ??aµµ?? fgets -
a?????s? µ?a? ??aµµ?? µe ?a?a?t??a a??a???
??aµµ?? fprintf - e???af? µ??f?p???µ????
ded?µ???? fscanf - a?????s? µ??f?p???µ????
ded?µ???? textscan - a????s? µ??f?p???µ????
ded?µ???? ap? a??e?? text textread - a????s?
µ??f?p???µ???? ded?µ???? ap? a??e?? text
??s?d??-???d?? d?ad???? a??e??? (binary files)
fread - a?????s? d?ad???? ded?µ???? fwrite -
e???af? d?ad???? ded?µ????
19
?s??s?
?ta? ? atµ?sfa??a e??a? se ap???t? ??eµ?a, ?
s??s? a??µesa st? ???? ap? t? ???assa (m) ?a? t??
atµ. ??es? (mbar) d??eta? st?? pa??p?e???
p??a?a. G???te t?? p??a?a se a??e?? m, mat,
xls. ?????ta? ???s? t?? a??e??? a?t?? ß?e?te
t?? p?es? se ???? 550 m ?a? t? ???? se p?es? 916
mbar.
???? ??s? p?es? (m) (mbar) 0 1013 100
1001 200 989 300 977 400 965 500 959 600
942 700 932 800 921 900 902 1000 894
20
G?af??? st? Matlab
2D Plots 2½D Plots 3D Plots Really 3D
Plots Movies Images
21
??sd??stata G?af???
(ap????e???µe ?? a??e?? .fig ??a µe????t????
a??a???)
x linspace(0,2pi,30) y sin(x) plot(x,y) ti
tle(Sine Plot) xlabel(x-axis) ylabel(y-axis
)
- ???s??t??µe ?e?µe?? - d?a??sµata - ??aµµ??
?p????e???µe, e?t?p????µe, ??p.
?e?e?????µe ?a? pe??st??f??µe
22
??sd??stata G?af???
??p?? ???? ??a ?a ??s??µe d??f??a ?a?a?t???st???
t?? ??af?µat??
23
??sd??stata G?af???
z cos(x) plot(x,y,bp,x,z,r-) Legend(sin
,cos) title(sin(sqrt(x_\delta2 y_\xi2))/sqr
t(x_\omega2 y_\eta2))
24
?a?a?t???st??? G?aµµ??
25
????ap?? G?af???
26
????ap?? G?af???
subplot(2,3,1) plot(x,y,bp,x,z,r-) axis
normal subplot(2,3,2) plot axis ij axis
square axis equal axis tight axis off
27
????ap?? G?af???
28
??sd??stata G?af???
y linspace(0,2pi,100) x sin(2x) polar(x,y)

29
21/2 D G?af???
X,Y,Z peaks(30) pcolor(Z)
30
21/2 D G?af???
31
21/2 D G?af???
contour(Z) contour(Z,50) contour(Z,50,k) c, h
contour(Z) clabel(c, h)
32
??a??sµata
load wind x x(,,4) y y(,,4) cav
curl(x,y,u,v) pcolor(x,y,cav) shading
interp hold on quiver(x,y,u,v)
33
????µata
mesh(X,Y,Z)
34
3D G?af???
surf(X,Y,Z) shading interp
35
3D G?af???
t 0pi/5010pi plot3(sin(t),cos(t),t) hold
on plot3(sin(t),cos(t),t1) hold off
36
3D G?af???
x,y,z sphere(16) X x()5x().75x()
Y y()5y().75y() Z
z()5z().75z() plot3(X,Y,Z) view(-10,60)
37
3D G?af???
scatter3(X(),Y(),Z(),.)
38
?????e?
Write a Comment
User Comments (0)
About PowerShow.com