Download presentation
Presentation is loading. Please wait.
1
MATLAB 해설 전자공학과
2
Number and Basic variables
Ans %답 Eps % 가장 작은수 pi = π Flops % 부동연산의 횟수 i or j = sqrt(-1) inf = 무한대 NaN=숫자가 아님 Realmin, realmax % 가장 작은(큰) 양의 실수
3
Array & Matrices x=[1, 2, 3]; x=[1 2 3] %1x3 vector
k=[1;2;3] %3x1 vector y=[1+j, 2+pi*i, -sqrt(-1)] A=[1 2 3; 4 5 6; 7 8 9] or A=[1,2,3;4,5,6;7,8,9] % 3x3 matrix t=[0:0.1:10] % generates a row vector t that increases from 0 % to 10 in increments of 0.1
4
Matrices length(x) % returns the dimension of a vector x
Size(A) % compute the row & column of A x(3) A(2,3) x(2:3) A(1:2, 3)
5
M-files: Scripts and Function Files
Script m-file test1.m Function m-file function [out1,out2, ...]=filename(in1,in2, ...) test2.m nargin, nargout
6
example File1.m ---- Script m-file Addiff.m---- function m-file
[a,b]=addiff(2,4); save result.dat a b –ascii %저장 sprintf(‘sum =%d\ndiff=%d’,a,b) %화면에 표시 Addiff.m---- function m-file function [isum, idiff] = addiff(a,b) %이 프로그램은 두수의 합과 차를 %구하는 프로그램입니다. if nargin ~= 2 error; end if nargout ~=2 error; end isum=a+b; idiff=abs(a-b);
7
Mathematical Operations and Functions:
Lower Case letter +, -, *, /, \, ^ (power), ' (transpose) 5^2, 22/2, 2\22 log, log10, exp, sqrt, det (determinant) inv, eig, rank real, imag, abs, conj
8
Basic Functions sin, cos, tan, asin : arcsine
acos, atan, sinh, cosh, tanh, asinh abs : 절대치, sqrt : 제곱근, real : 실수부 imag : 허수부, conj : 공액복소수 round : 반올림, fix : 버림 sign : signum, rem : 나머지 exp : 밑이 e인 지수, log : 자연로그 log10 : 상용로그
9
Relational Operators < less than <= less than or equal == equal
> greater than >= greater than or equal ~= not equal xor
10
Logical Operators & % AND | % OR ~ % NOT
11
Loops and Conditional Structures
for While If~else Switch ~ Case
12
For loop for variable=expression statement; ... end
13
Example For k=1:20 x(k) = sin(k*2*pi/20); End x
14
WHILE Loop while expression statement; ... end
15
Example N! 구하기 N=5;i=1; R=1; while i<=N R=i*R i=i+1; end R
16
IF, ELSE, ELSEIF if expression, statement, ... , statement, ...
elseif expression2, statement, ... , statement, ... , else statement, ... . end
17
Example while 1 disp('*********Menu***************') disp('* A: *')
disp('* B: *') disp('* C: *') disp('****************************') n=input('Type string : ','s'); if n == 'A' disp('You typed A') elseif n == 'B' disp('You typed A') elseif n == 'C' disp('You typed C') else disp('Please type character in the menu') end
18
example while 1 n=input('Type any number(99:exit) : ');
if n==99 break; end sprintf('You typed number %d',n) end sprintf('You typed number %d, Bye!',n)
19
CASE SWITCH statement CASE is part of the SWITCH statement syntax, whose general form is: SWITCH switch_expr CASE case_expr, statement, ..., statement CASE {case_expr1, case_expr2, case_expr3,...} ... OTHERWISE, END
20
example aaa =4; switch aaa case 1, disp('Number is 1')
otherwise, disp('Number is out of 1-9') end
21
Plotting and Graphics plot, loglog, semilogx, semilogy, polar
t=0:2*pi*2/50:2*pi*2*2; Y=sin(t); Plot(t,Y) Subplot(232);plot(t,Y) legend(‘sine(t)’) legend off
22
4. Plot (계속) title('Title of the Figure'), xlabel('X-axis Label')
ylabel('Y-axis Label') gtext('Text for annotation') % for mouse positioned text text(x, y, 'Text for annotation'), grid
23
Matlab Workspace Who Whos Clear variables Help clear
Diary filename: 입력 및 명령창 출력을 파일로 저장 Diary off Cd Dir !dos command
24
Matlab Workspace (내장 명령어)
what Type Clock Date lookfor
25
데이터의 저장과 복원 File/save workspace as… File/load workspace as… Save
Save file1 a b c Save file2 a b c -ascii Load Load file1 Load file2 -ascii
26
Strings Str = ‘Suwon univ’; Size(Str) U=Str(4:7) U=Str(9:-1: 5) disp('text string') disp(Str)
27
String Functions Base2dec Bin2dec Char Dec2base Dec2bin Dec2hex double
28
String Functions Fprintf Hex2dec Hex2num Int2str Sprintf Sscanf
str2num
29
File I/O(FPRINTF, SSCANF, FGETL, FGETS, FREAD, INPUT)
Opening and closing files example : fid =fopen('pen.dat','r') 'r' : reading 'w' : wrighting 'a' : appending 'r+' : reading and wrighting status = fclose(fid); status = fclose('all'); ( 0 : successful, -1 : unsuccessful )
30
File I/O Reading Binary Data Files fread : reads binary data files
example : fid = fopen('penny.dat', 'r'); A = fread(fid); status = fclose(fid);
31
Controlling Position in a File
Writing Formatted Text Files and Strings %e for exponential notation %f for fixed point notation %g which automatically selects the shorter of %e and %f Reading Formatted Text Files and Strings %s to match a string %d to match a decimal number %f to match a floating point value
32
Matlab Debugger dbstop : set breakpoint dbclear : remove breakpoint
dbcont : resume execution dbstack : list who called whom dbstatus : list all break point dbstep : execute one or more lines dbtype : list M-file with line numbers dbup : change local workspace context dbquit : quit debug mode
33
control system signal processing neural network Communications …….
Toolboxes control system signal processing neural network Communications …….
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.