Presentation is loading. Please wait.

Presentation is loading. Please wait.

응용 전산 및 실습 MATLAB – Chapter 4 그래픽

Similar presentations


Presentation on theme: "응용 전산 및 실습 MATLAB – Chapter 4 그래픽"— Presentation transcript:

1 응용 전산 및 실습 MATLAB – Chapter 4 그래픽
위덕대학교 에너지전기공학부 이 성 환 Chapter 4 Uiduk University

2 MATLAB – Scripting M-File
REVIEW MATLAB 메뉴의 File  New  M-File 선택 M-File Editor 가 실행되며 다음과 같이 화면에 나타남 원하는 MATLAB 명령어 입력 (명령어 입력 시 절대 한글을 사용하지 말 것!) File  Save 를 선택하고 원하는 경로에 원하는 파일 이름으로 저장 (파일 이름에 절대 한글을 쓰지 말 것!) Debug  Run 을 선택하여 생성한 M-File을 실행하면 MATLAB Command Window에 결과가 나타남 Chapter 4 Uiduk University

3 MATLAB – Array Definition MATLAB – Array Calculation
REVIEW Keyword Meaning [ ] 배열의 시작과 끝 ; 행 구분 , 열 구분 MATLAB – Array Calculation Operation Symbol Example Addition, a + b + A + B Subtraction, a – b - A – B Multiplication, a • b * A * B Division, a  b / or inv() A / B = A * inv(B) Exponentiation, ab ^ A ^ 2 Transposition, aT A’ Chapter 4 Uiduk University

4 MATLAB – Scalar and Array Operation
REVIEW Element-By-Element Operation Representative Data Scalar Addition Scalar Multiplication Array Addition Array Multiplication Array Division Array Exponentiation Chapter 4 Uiduk University

5 MATLAB – Easy Array Construction
REVIEW Array Construction Technique Description x = [ 2, 2*pi, sqrt(5), 2-3j ] Create row vector x containing element specified x = first : last Create row vector x starting with first, counting by one, ending at or before last x = first : increment : last Create row vector x starting with first, counting by increment, ending at or before last x = linspace(first, last, n) Create row vector x starting with first, ending at last, having n elements x = logspace(first, last, n) Create logarithmically-spaced row vector x starting with 10first, ending at 10last, having n elements Chapter 4 Uiduk University

6 MATLAB – Easy Array Construction
REVIEW EX1) >> c = [1, 6, 9, 7] c = >> a = 1 : 5 a = >> b = 1 : 2 : 7 b = >> x = (0 : 0.1 : 0.3) * pi x = EX2) >> d = [ a(1:2:5), 1, 0, 1 ] d = >> a = 1 : 3, b = 1 : 2 : 7 a = b = >> c = [ b, a ] c = EX3) >> x = linspace(2, 6, 3) x = >> x = logspace(0, 2, 11) Chapter 4 Uiduk University

7 MATLAB – Reading From Data File
REVIEW << mat.txt>> 파일의 내용 >> load mat.txt >> t = mat( : , 1); % 시간 벡터 >> x = mat( : , 2); % 변위 벡터 >> v = mat( : , 3); % 속도 벡터 >> a = mat( : , 4); % 가속도 벡터 Chapter 4 Uiduk University

8 MATLAB – Plot Procedure
Plot 할 데이터 준비 (x, y 축의 데이터 생성 / Reading Data) Single graphic / Multi graphic 선택 Plot 함수 호출 Line 이나 marker 의 속성 선택 축의 한계값, grid line 등을 설정 xlabel, legend, text 등으로 라벨링 그래픽 객체 출력 Chapter 4 Uiduk University

9 MATLAB – Single Plot (1) Plot 할 데이터 준비 >> x = 0:0.01:10;
>> y = sin(x) .* cos(x + pi/2); >> size(x) ans = >> size(y) Single graphic / Multi graphic 선택 >> figure(1) Chapter 4 Uiduk University

10 MATLAB – Single Plot (2) Plot 함수 호출 >> plot(x, y);
Line 이나 marker 의 속성 선택 >> set(plot(x,y), 'LineStyle', '--'); Chapter 4 Uiduk University

11 MATLAB – Single Plot (3) 축의 한계값, grid line 등을 설정
>> axis([1, 5, -0.5, 0]); >> grid on; xlabel, legend, text 등으로 라벨링 >> xlabel('x'); >> ylabel('y'); >> title('Plotting x and y'); 그래픽 객체를 출력 >> print –dbitmap d:\ex1.bmp >> print –djpeg d:\ex1.jpg >> print –dtiff d:\ex1.tif Chapter 4 Uiduk University

12 MATLAB – Plot Function (Linear Plot)
Form Meaning Plot(y) Plots the columns of y versus their index Plot(x, y) Plots vector y versus vector x Plot(x, y, s) s is a character string made from the table on the next page Plot(x1, y1, s1, x2, y2, s2, … ) Combines the plots defined by the (x, y, s) triples Chapter 4 Uiduk University

13 MATLAB – Plot Options Color Point Mark Line Style b blue . point -
solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed m magenta * star y yellow s square k black d diamond v triangle(down) ^ triangle(up) < triangle(left) > triangle(right) p pentagram h hexagram Chapter 4 Uiduk University

14 MATLAB – Plot Example (1)
>> y = [1, 6, 9, 7] ; >> plot(y); EX2) >> y = [1, 6, 9, 7] ; >> plot(y, 'rs:'); Chapter 4 Uiduk University

15 MATLAB – Plot Example (2)
>> y = x.^3 - 6*x.^2 + 11*x - 6; >> plot(x, y); >> axis([0, 4, -5, 5]); EX4) >> x = 0:0.01:10; >> y = x.^3 - 6*x.^2 + 11*x - 6; >> plot(x, y, 'b:'); >> axis([0, 4, -5, 5]); Chapter 4 Uiduk University

16 MATLAB – Plot Example (3)
>> y = x.^3 - 6*x.^2 + 11*x - 6; >> plot(x, x – x, x, y); >> axis([0, 4, -5, 5]); EX6) >> x = 0:0.01:10; >> y = x.^3 - 6*x.^2 + 11*x - 6; >> y1 = 3 * sin(3.*x); >> plot(x, x - x, 'k-', x, y, 'b-.', x, y1, 'k-'); >> axis([0, 4, -5, 5]); Chapter 4 Uiduk University

17 MATLAB – SubPlot Function
Form Meaning subplot(m, n, i) Breaks the Figure window into an m X n matrix of small axis and selects the i’th axis for the current plot subplot(mni) EX7) >> x1 = 0:0.1:10; >> f1 = sin(x1) .* cos(x1 + pi / 2); >> subplot(221); >> plot(x1, f1); >> x2 = 0:0.1:100; >> f2 = x2.^ *x2.^3 + 10*x2.^2 - 30*x2 + 5; >> subplot(222); >> plot(x2, f2); >> x3 = 0:0.1:100; >> f3 = -(0.4*x3.^3).*sin(x3); >> subplot(223); >> plot(x3, f3); >> grid on; >> xlabel('x3'); >> ylabel('y3'); >> x4 = 1:1:200; >> f4 = sqrt(x4).*log(x4); >> subplot(224); >> plot(x4, f4); Chapter 4 Uiduk University


Download ppt "응용 전산 및 실습 MATLAB – Chapter 4 그래픽"

Similar presentations


Ads by Google