#title MATLAB 강의 DAY 1 [[TableOfContents]] Course Outline * Matlab Environment Tools * Vector / Matrix Handling 참고 사이트 : www.matlabcc.com == Matlab 맛보기 == {{{#!plain matlab % 마방진 >> A = magic(3) A = 8 1 6 3 5 7 4 9 2 % 역행렬 >> B = inv(A) B = 0.1472 -0.1444 0.0639 -0.0611 0.0222 0.1056 -0.0194 0.1889 -0.1028 >> A*B ans = 1.0000 0 -0.0000 -0.0000 1.0000 0 0.0000 0 1.0000 %Deteminent(?) >> det(A) ans = -360 % Eigen Value >> [V, D] = eig(A) V = -0.5774 -0.8131 -0.3416 -0.5774 0.4714 -0.4714 -0.5774 0.3416 0.8131 D = 15.0000 0 0 0 4.8990 0 0 0 -4.8990 %help comet을 치면 나오는 예제. 애니메이션 그래프가 출력된다. >> t = -pi:pi/200:pi; >> comet(t,tan(sin(t))-sin(tan(t))) >> peaks >> vibes }}} == C언어와 Matlab의 프로그래밍 스타일 == C언어는 순차적으로 연산해서 뿌려주는데 반해, Matlab은 모든 계산을 끝내고 뿌려준다. == MS word와의 연동 == 1. >> notebook : MS word 실행 1. Matlab 함수 타이핑 → 마우스로 긁어서 블럭지정 → 우클릭 메뉴 불러오기 → Evaluate Cells → 해당 함수가 수행되며, 결과가 자동으로 MSword에 삽입된다. 1. plot을 수행할 경우 그래프도 자동으로 포함된다. attachment:msword_matlab.png == Shortcut Toolbar == 자주 사용하는 Shortcut을 등록해서 사용할 수 있다. Shortcut Toolbar위에서 우클릭 메뉴를 불러온 뒤, New Shortcut을 클릭하면 새로운 Shortcut을 생성할 수 있다. attachment:shortcut_toolbar.png == Cell Toolbar == Matlab Editor에서 주석문자인 %%을 사용해서 Cell을 구분할 수 있다. 한 Editor안에서 구분된 Cell은 따로 실행할 수 있다. attachment:cell_toolbar.png %를 하나만 사용할 경우에는 주석으로만 사용된다. == Usefull Command == === Help (도움말 사용하기) === ==== lookfor ==== 함수명은 모르지만, 핵심 키워드는 알고 있을 경우 사용하는 함수명 검색 명령 {{{#!plain matlab >> lookfor fourier FFT Discrete Fourier transform. FFT2 Two-dimensional discrete Fourier Transform. FFTN N-dimensional discrete Fourier Transform. IFFT Inverse discrete Fourier transform. IFFT2 Two-dimensional inverse discrete Fourier transform. IFFTN N-dimensional inverse discrete Fourier transform. fi_radix2fft_demo.m: %% Fixed-Point Fast Fourier Transform (FFT) DFTMTX Discrete Fourier transform matrix. SPECGRAM Spectrogram using a Short-Time Fourier Transform (STFT). SPECTROGRAM Spectrogram using a Short-Time Fourier Transform (STFT). FFT Quantized Fast Fourier Transform. FOURIER Fourier integral transform. IFOURIER Inverse Fourier integral transform. }}} lookfor fourier -all 을 사용하면 관련된 모든 함수가 출력된다. ==== help ==== 함수명을 알고 있으며, command window에서 간단한 설명을 보고 싶을 때 사용 {{{#!plain matlab >> help fft FFT Discrete Fourier transform. FFT(X) is the discrete Fourier transform (DFT) of vector X. For matrices, the FFT operation is applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and truncated if it has more. FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the dimension DIM. For length N input vector x, the DFT is a length N vector X, with elements N X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N. n=1 The inverse DFT (computed by IFFT) is given by N x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N. k=1 See also fft2, fftn, fftshift, fftw, ifft, ifft2, ifftn. Overloaded functions or methods (ones with the same name in other directories) help uint8/fft.m help uint16/fft.m help qfft/fft.m help iddata/fft.m Reference page in Help browser doc fft }}} ==== doc ==== 함수에 대한 자세한 설명을 Help window를 통해 보고 싶을 때 사용. >> doc fft === Tab === Command Window, Editor에서 명령어 일부를 타이핑하고 Tab을 누르면 관련 명령 목록이 주르륵 나타난다. 명령어 안의 변수들도 Tab을 사용할 수 있다. attachment:tab.png === Source는 숨기고, 기능만 전달하기 === m cde을 p code로 변환하면, 안의 Source는 확인할 수 없다. === C code를 Matlab의 lcc로 컴파일하기 === lcc 관련 setting이 필요 컴파일한 C code는 matlab 함수와 같은 방법으로 사용할 수 있다. === whos === 저장된 데이터의 Name, size, Bytes, class, Attribute 정보를 보여준다. {{{#!plain matlab >> whos Name Size Bytes Class Attributes A 1x1 8 double B 3x3 72 double }}} attachment:whos.png === Close === close close all close hidden close hidden all === clear === clear all : workspace의 모든 데이터를 삭제한다. === clc === clc : Command Window의 모든 텍스트를 삭제한다.