Chiusakpung's Electronics Blog

블로그 이미지
Computer programming ...
by 치우삭풍
  • Total hit
  • Today hit
  • Yesterday hit

'EECS/MATLAB'에 해당되는 글 7건

  1. 2009.04.01
    Fast Fourier Transform & Inverse Fast Fourier Transform [연습용]
  2. 2009.04.01
    Intrinsic Charge Carrier Density n_i vs. Absolute Temperature T
  3. 2008.10.18
    Section 1-1. What is MATLAB, MATLAB Desktop Tools
  4. 2008.10.18
    MATLAB Online Learning Center
  5. 2008.10.03
    MATLAB - Some useful problems for Basic Signal Description
  6. 2008.08.11
    MATLAB 프로그래밍 - 2. 제어 흐름
  7. 2008.08.06
    MATLAB 프로그래밍 - 1. 매트랩 환경

%% = Bandpass Filter:
clear, clc
freq = [1, 2, 3, 4, 5];
angfreq = 2 * pi * freq;
t = 0 : 0.001 : 10;
x = sin(angfreq(1) * t) + sin(angfreq(2) * t) + sin(angfreq(3) * t) + sin(angfreq(4) * t) + sin(angfreq(5) * t);
[num, den] = butter(3, [0.1, 0.2]);
y = filter(num, den, x);
subplot(2,1,1); plot(t,x);
subplot(2,1,2); plot(t,y);

%% DFT using FFT function

clear, clc
t = 0:0.001:0.6;
x = sin(2*pi*50*t)+sin(2*pi*120*t);
y = x + 2*randn(size(t));
subplot(2,1,1); plot(1000*t(1:50),y(1:50));
title('Signal Corrupted with Zero-Mean Random Noise');
xlabel('time (milliseconds)');

Y = fft(y,512);
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
subplot(2,1,2); plot(f,Pyy(1:257));
title('Frequency content of y');
xlabel('frequency (Hz)');

%% DFT using FFT function - sin & cos
% Samping Rate
% Sampling frequency fs
% > twice highest frequency of input
% signal! )

clear, clc
fs = 100; Ts = 1/fs; Nf = 1000;
t = 0:Ts:10;
x = sin(2 * pi * 2 * t);
X = fft(x,Nf);
Pxx = X.*conj(X);
f = fs * (0:(Nf/2))/Nf;
subplot(4,1,1); plot(t,x); title('Input signal x(t)'); xlabel('time t(s)');
subplot(4,1,2); plot(f, Pxx(1:(Nf/2) + 1)); title('Output signal X(f) - Fourier transform of x(t)'); xlabel('freq f(Hz)');
x2 = ifft(X, Nf);
subplot(4,1,3); plot((1:Nf)*Ts,x2); title('x_2(t) - Inverse Fourier Transfrom of X(f)');
subplot(4,1,4); plot((1:Nf)*Ts, x(1:Nf) - x2); axis([1*Ts, Nf*Ts, -1,1]); title ('Difference betw. x(t) & x_2(t)');

%% Creation of Transfer Function of BPF by tf & bode
clear, clc
wL = 2 * pi * 1000;
wH = 2 * pi * 5000;
gain = 10;
H = tf([1 0], [1/251340, 1/gain, 785.4003]);


%subplot(2,2,1); plot(f, H); % plot real(H)
%subplot(2,2,2); plot(f, H .* conj(H));
%subplot(2,2,3); plot(f, abs(H)); % plot |H(f)|
%subplot(2,2,4); plot(f, angle(H)); % plot ∠H(f)
%subplot(2,1,2);
bodeH = bodeplot(H);
setoptions(bodeH,'FreqUnits','Hz');
grid;
bandwidth(H)

%% Bandpass Filter
clear, clc
% Variables for Bode plotting - Range of freqeuncy (Hz) & Gain
Lorder = 1;
Horder = 5; 
gain = 10;

% Domain Setting
tmax = 0.05; tstep = 0.00001;
fmax = 50000; fstep = 1;
t = - tmax : tstep : tmax;
f =  (10^Lorder) - 9 : (10^Horder);  % - 9 for even number points
w = 2 * pi * f;

 % Nf  = Number of points for FFT         = size of X(f)  =  size of
 % frequency domain 'f' = size of H(f)

Nf = length(f);   
  

% for Plotting X(f) if dScaling = 3/5, the domain of frequency  : 1 ~ 50000
% * 3/5 = 1~30000 Hz

dScaling = 3/5;

% Transfer Function
% Gain : 10
% Cut-off 3dB freq : low = 1 kHz, high = 5 kHz
wL = 2 * pi * 1000;
wH = 2 * pi * 5000;

H_tf = tf([1 0], [1/251340, 1/10, 785.4003]);
H = (j * w) ./ (-w.*w/251340 + j*w/10 + 785.4003);

figure(1);
bodeH = bodeplot(H_tf);
setoptions(bodeH,'FreqUnits','Hz'); grid;

figure(2);
subplot(2,1,1); semilogx(w / (2 * pi), 20*log10(abs(H))); axis([10^Lorder, 10^Horder, -60, 20]); grid;  % plot Mag.
title('Bode plot of H(jw) - Not created by tf function');
ylabel('Magnitude (dB)');
subplot(2,1,2); semilogx(w / (2 * pi), unwrap(angle(H)) * 180 / pi); axis([10^Lorder, 10^Horder, -90,90]); grid; % plot Angle
ylabel('Angle (deg)');
xlabel('Freqeuncy (Hz)');
set(gca, 'YTick', -90 : 45 : 90);
set(gca, 'YTickLabel',{'-90','-45','0','45','90'});


% Initializing test signal x(t)
x = sin(2*pi*100*t) + sin(2*pi*200*t) + sin(2 * pi * 500*t);
x = x + sin(2*pi*1000*t) + sin(2*pi*2000*t) + sin(2*pi*5000*t);
x = x + sin(2*pi*10000*t ) + sin (2*pi*20000*t);

% X(f) = FFT {x(t)}s
X = fft(x, Nf);

% Output signal Y(f) = H(f)X(f) <-> y(t) = h(t) * x(t)
%size(H), size(X)

Y = H .* X;

MagX = abs(X);
MagY = abs(Y);

figure(3);
subplot(2,2,1); plot(t, x); title('Test Signal x(t)'); xlabel('time t (s)');
subplot(2,2,2); plot(w/(2*pi), abs(H)); title('Transfer Function H(f)'); xlabel('freqeuncy f (Hz)'); ylabel('Mag. (Not dB)');
subplot(2,2,3); plot(f(1: Nf/2 * dScaling), MagX(1: Nf/2 * dScaling)); title('Not filtered signal |X(f)| - Fourier Transformed'); xlabel('frequency f (Hz)'); grid;
SeeFreq_100_Hz = 0; % 1 for yes, 0 for no
subplot(2,2,4); plot(f(1 : Nf/2 * dScaling), MagY(1 : Nf/2 * dScaling)); title('Fitered signal |Y(f)| = |H(f)||X(f)|'); xlabel('frequency f (Hz)'); grid;
xlim([1,25000*(1 - SeeFreq_100_Hz) + 2500 * SeeFreq_100_Hz]);
set(gca, 'YTick', [50000/11, 50000/6, 50000/5, 50000/sqrt(7), 35355, 50000]);
set(gca, 'YTickLabel',{'50000/11', '50000/6', '50000/5', '50000/√7','50000/√2','50000 (Gain = x10)'});


% Inverse Fast Fourier Transforms
y = ifft(ifftshift(Y));
tScaling = 1/Nf;

figure(4);
Magy = real(y);
subplot(2,1,1); plot(tScaling * (0:length(Magy) - 1), Magy); title('Output Signal y(t)'); xlabel('time t(s)');axis([0,0.005,-25,25]);

xfilt = 50000/11 * sin(2*pi*100*t) + 50000/6*sin(2*pi*200*t) + 50000/sqrt(7)*sin(2 * pi * 500*t);
xfilt = xfilt + 35355 * sin(2*pi*1000*t) + 50000*sin(2*pi*2000*t) + 35355 * sin(2*pi*5000*t);
xfilt = xfilt + 50000/sqrt(7) *sin(2*pi*10000*t ) + 50000/5*sin (2*pi*20000*t);
xfilt = xfilt/50000;
xfilt = xfilt * 10; % Gain = 10;

subplot(2,1,2); plot(t,xfilt); title('Expected Output Signal y(t)'); xlabel('time t(s)'); axis([0,0.005,-25,25]);

%close(1);
%close(2);
%close(3);
%close(4);

AND

[소스코드]

% EE302A HW3-5
%% Calculate n_i for Si, GaAs and Ge

clear
clc

Nc = [2.8 * 10^19, 4.7 * 10^17, 1.04 *10^19];
Nv = [1.04 * 10^19,7.0 * 10^18, 6.0 * 10^18];
Eg = [1.12, 1.42, 0.66];

k300eV = 0.0259;
T = linspace(200, 600, 10000);
kT = k300eV * T / 300;

N = Nc .* Nv;

ni_Si = sqrt(N(1) * (T/300).*(T/300).*(T/300) .* exp( - Eg(1) * ones(size(kT)) ./ kT));
ni_GaAs = sqrt(N(2) * (T/300).*(T/300).*(T/300) .* exp( - Eg(2) * ones(size(kT)) ./ kT));
ni_Ge = sqrt(N(3) * (T/300).*(T/300).*(T/300) .* exp( - Eg(3) * ones(size(kT)) ./ kT));

OverT = 1000 * ones(size(T)) ./ T;

semilogy(T , ni_Si, T , ni_GaAs, T , ni_Ge);
xlabel('Temperature T [K]');
ylabel('Intrinsic Charge Carrier Density n_i [#/cm^3]');

[실행결과]

사용자 삽입 이미지

AND

What is MATLAB?

- Computation
: Matrix/Array Based Numerical Analysis

- Visualization
: Simple & Powerful Graphical Works
example)
comet
peaks
sr5demo1
vibes
logo

- Programming
High Level Language for Engineering

- External Links with C, MS Office(Excel, Word... )
example)
notebook

MATLAB Desktop Tools
Current Directory Browser
: filebrowser, dir, cd, delete

Workspace Browser
: workspace, whos

Command History
: commandhistory, diary

Path Browser
: pathtool, path, addpath, rmpath

Launch Pad - Start Button

  
  
   
AND


Course Outline of Basic MATLAB Learning

Section1 : MATLAB Environment Tools
Section2 : Vector/Matrix Handling
Section3 : MATLAB Data Types
Section4 : Basic Programming Background

Section5 : Basic Visualization
Section6 : Basic Data Processing
Section7 : MATLAB-specific Symbols
Section8 : MATLAB-style Coding Skills

AND


Signals and Systems by M. J. Roberts

1) Using MATLAB, garph these function combinations, p 42

t = 0 : 1/120 : 6        % make vectors with values from 0 to 6 with the step 1/120.
x1 = exp(-t).*sin(20*pi*t) + exp(-t/2) .* sin(19*pi*t);

subplot(2,1,1); p = plot(t, x1, 'k'); set(p, 'LineWidth', 2);
xlabel('\itt'); ylabel('x_l({\itt})');             %   { } determines the range of the effect of \it  (italic font)

t = -4 : 1/60 : 4 ; x2 = sinc(t) .* cos(20*pi*t);
subplot(2, 1, 2); p = plot(t, x2, 'k'); set(p, 'LineWidth', 2);
xlabel('\itt'); ylabel('x_2({\itt})') ;

2) Program to illustrate some of MATLAB's built-in functions, p60

close all;

t = -20 : 1/20 : 20;

x1 = chirp(t, 1/20, 20, 1/3); subplot(4,2, 1); p = plot(t, x1, 'k');
axis([-20, 20, -1.5 1.5]); title('chirp - A "chirped" cosine');
xlabel('\itt'); ylabel('x_1({\itt})');

x2 = diric(t, 5); subplot(4,2,2); p = plot(t, x2, 'k');
axis([-20,20,-1.5,1.5]);
title ('diric - The MATLAB "Dirichlet" function');
xlabel('\itt'); yabel('x_2({\itt})');

x3 = sawtooth(t); subplot(4,2,3); p = plot(t, x3, 'k');
axis([-20,20,-1.5,1.5]); title('sawtooth - A Periodic Sawtooth');
xlabel('\itt'); ylabel('x_3({\itt})');

x4 = square(t); subplot(4,2,4); p = plot(t, x4, 'k');
axis([-20,20,-1.5,1.5]); title('square - A Square Wave');
xlabel('\itt'); ylabel('x_4({\itt})');

x5 = rectpuls(t); subplot(4,2,5); p = plot(t, x5, 'k');
axis([-20,20,-1.5,1.5]); title('rectpuls - A Rectangular Pulse');
xlabel('\itt'); ylabel('x_5({\itt})');

x6 = tripuls(t); subplot(4,2,6); p = plot(t, x6, 'k');
axis([-20,20,-1.5,1.5]); title('tripuls - A Triangular Pulse Wave');
xlabel('\itt'); ylabel('x_6({\itt})');

x7 = sinc(t/2); subplot(4,2,7); p = plot(t, x7, 'k');
axis([-20,20,-1.5,1.5]); title('sinc(t)');
xlabel('\itt'); ylabel('x_7({\itt})');

x8 = sign(t/2); subplot(4,2,8); p = plot(t, x8, 'k');
axis([-20,20,-1.5,1.5]); title('sign - The Signum Function');
xlabel('\itt'); ylabel('x_8({\itt})');

---------------------------------------------------------------

x1e = (x1 + x1(end : -1 : 1) ) /2 ; x1o = (x1 - x1(end : -1 : 1) ) /2;      % x1 is a matrix !! so, the step of
                                                                                                 % index is -1, not a fraction
subplot (2,1,1); plot( t, x1e, 'k');
axis([-20,20,-1.5,1.5]); title('Even part of x_1');
xlabel('\itt'); ylabel('x_1_e({\itt})');
subplot (2,1,2); plot( t, x1o, 'k');
axis([-20,20,-1.5,1.5]); title('Odd part of x_1');
xlabel('\itt'); ylabel('x_1_o({\itt})');


3) Discrete Signals, p80

function y = g(n)
     ss = find(n ~= round(n));
     n(ss) = NaN;                             % notice that n is not a variable in other languages.
                                                    % In MATLAB, all variables are MATRICES with (INDICES)
   
y = 10*exp(-n/4).* sin(3 * pi * n / 16) .* uDT(n);

function y = uDT(n)
     ss = find(n ~= round(n));
     y = double(n >= 0);
     y(ss) = NaN;



>> n = -5:48;
>> g0 = g(n);
>> g1 = g(2*n);
>> g2 = g(n/3);
>> subplot(3,1,1);
>> p = stem(n, g0, 'k', 'filled');
>> set(p, 'LineWidth', 2, 'MarkerSize',4);
>> ylabel('g[n]'); title('Example 2.5');
>> subplot(3,1,2);
>> p = stem(n, g1, 'k', 'filled');
>> set(p, 'LineWidth', 2, 'MarkerSize', 4);
>> ylabel('g[2n]');
>> subplot(3,1,3);
>> p = stem(n, g2, 'k', 'filled');
>> set(p, 'LineWidth', 2', 'MarkerSize',4);
>> ylabel('g[n/3]');

AND

매트랩(MATLAB)

연산의 기본 자료형이 행렬인 고수준(High-level) 프로그래밍 언어

2.1-3 If - elseif - else - end 문
 
      MATLAB에서의 조건연산자는 다음과 같다.
      >
      >=
      <
      <=
      ==
      ~=        : '같지 않다.' 나머지는 ANSI C를 따르나 '같지 않다'만 다르다. (C언어에서는 !=)

     ※ 난수 발생 예
 
      ceil(10*rand(1))

     MATLAB에서의 논리연산자는 ANSI C에서의 비트 연산자와 같다.
     & : and
     | :  or
     ~ : not
     단, xor에 해당하는 연산자가 없어 xor이라는 함수를 제공된다.
     사용법 : xor( (x>2) , y == 5 )
                 xor( (a>b), (y<=1) )

     if 문의 구조는 다음과 같다.

     if 조건문
               명령문;
     [else if 조건문
              명령문]

     [else
           명령문]
      end
 
      ※ 배열을 깔끔하게 출력하는 방법 : disp(변수);
      ※ 실수인가? isreal(변수);

2.4 switch case 문

      swtich 표현식
            case 값1                       % 값에는 스칼라 혹은 문자열이 될 수 있따. 여러 값도 올 수 있는데 이때는
                   명령어들                 % {값1, 값2, 값3 ... }와 같이 쓴다.
            case 값2
                   명령어들
            otherwise
                   명령어들
      end

2.5 for 문


     

AND

매트랩(MATLAB)

연산의 기본 자료형이 행렬인 고수준(High-level) 프로그래밍 언어

1.1 계산기로서의 매트랩

     파이썬과 같은 인터프리터형 언어. 따라서 가장 간단한 용도가 계산기이다.
     연산자의 부호는 ANSI C를 따른다.

1.2 변수 정의

     변수 명은 19자 까지 가능하며 문자, 숫자 그리고 밑줄 문자를 사용할 수 있다.
    
     ※ 현재 메모리에 저장된 변수를 보기 위해서는 who 명령을 사용한다.
         whos : who의 두 번째 형식의 명령으로 메모리에 저장된 명령 목록과 각 변수가 사용한 메모리 량을 보여준다.
         그 외 Workspace 탭에서 메모리에 저장된 변수를 확인할 수 있다. (whos 형식으로 보여줌)

     matrix의 정의
     : 같은 행 원소끼리 스페이스 바 한 칸, 행 분리는 세미콜론(;)
   
     >> m = [1 2 3 4; 5 6 7 8; 9 10 11 12]                

     m =
               1        2        3        4
               5        6        7        8
               9      10       11       12


      변수들의 초기화 명령 : clear

1.3 함수   -   3 장에서 더 자세히 다룬다.

1.4 표시 포멧
   
     help format
    
     예) 다른 포맷을 사용하여 표시된 pi 값

      format short          3.1416                           디폴트 표시
      format long           3.14159265358979            16 숫자
      format short e       3.1416e+000                    5 숫자 + 지수
      format long e        3.14159265358979            16 숫자 + 지수
      format hex            400921fb54442d18            16 진수
      format bank           3.14                              소수점 이하 2자리 (통화)
      format +                 +                                  양수, 음수, 0
      format rat               355/133                        정수 비 (분수)



1.5 메모리 저장 변수를 파일에 저장하기

      명령어 - save [파일명] / load [파일명]


1.6 미리 정해진 변수
   
      Inf ( inf ) : 변수 inf는 수치를 표시하지 않지만 숫자로 취급됨을 주의할 것.

      => 무한 값이 포함된 계산을 하는 경우 결과는 무한대가 된다.

      NaN : 정의되지 않는 무효의 연산시 나오는 결과.         예)  0/0 ,    ∞/∞ ,  ∞ x 0 등

      => NaN 이 포함된 결과는 모두 NaN이 된다.

     그 외

     ans   :   최근 계산 값
     pi      :   원주율
     eps   :   컴퓨터에서 1에 더해졌을 때 1보다 큰 실수를 만든늧 ㅚ소의 숫자
     realmin  : 사용가능한 양의 최소값
     realmax : 사용가능한 양의 최대값

1.7  복소수

      MATLAB에서 순수한 허수와 복수스는 문자 i 또는 j로 표현된다

      >> (1+2i) / (3+5i)
     ans =
              0.3824 + 0.0294i

     임의의 복소수 변수를 A라 할 때,
     실수부 함수 : real(A)
     허수부 함수 : imag(A)
     절대값 함수 : abs(A)
     편각 함수(rad)  : angle(A)    <-- 수학에서는 arg로 쓴다.( Argument )
     
     1.7.1 직교 및 극 좌표

          직교좌표계 ( x = a + bi)     극좌표계  x = M∠Θ=Me^{iΘ}

          MATLAB에서의 지수함수 : exp()

1.8 행렬과 벡터

     1.8.1 행렬 곱셈

      연산자 * 로 1. 스칼라 곱셈  2. 행렬끼리의 곱셈 모두 가능하다.

     1.8.2  행렬 덧셈과 뺄셈

      ※ 스칼라 덧셈
      >> A = [1 2; 3 4]
      A =
              1    2
              3    4

      >> A + 5
      A = 
              6    7
              8    9

      1.8.3  역행렬, 랜덤행렬, 행렬식, 랭크, 연립 방정식의 풀이

      inv(A),   rand(m[, n]),      det(A),    rank(A)
     
      ※ rand(m)은 m x m 정방행렬을 만들과 0과 1 사이의 임의의 수를 무작위로 채운다.
          rand(m, n)은 m x n 행렬.

      ※ 연립방정식의 풀이
          연립방정식 Ax = b   (A는 행렬, b는 벡터)이 주어졌을 때,
          Ax = b의 해가 존재한다는 것은  b가 column space of A 위에 있다는 뜻이다.
          그런데 어떠한 행렬에 가해지는 Elementary operation들은
          1) 행 벡터들이 만드는 Subspace를 변화시키지 않는다.
          2) 열 벡터들이 만드는 Subspace는 변하지만 열 벡터들 간의 관계(relation)은 변화시키지 않는다.

          또한 Rank Theorem에 의해 ( rank(A) = rank(A^T) = rank(A^T*A) = rank(A*A^T) )
          column space의 차원과 row space의 차원은 동일하다.
          따라서, A의 열벡터들의 Linear Combination으로 표현 가능한 b를 추가해서 만든 새로운 행렬
          [A b] 의 rank 또한 A와 같게 된다.

          즉 Ax = b is consistency if and only if rank(A) = rank([A b])
   
          만일 위의 검사가 긍정적인 결과라면 다음의 두 가지 방법으로 해를 구할 수 있다.

          1) x = inv(A) * b
          2) x = A\b <-- 역 슬래시 연산자   :  이 방법은 적은 수의 연산이 필요하므로 더 좋은 방법이고 1)번 보다 더 정확하다.


1.9 문자열

       >> x = 'abcd'
       x =
       abcd
       >> y = 'didn''t'
       y =
       didn't
       >> X = '''' <- 작은 따옴표 4개
       X =
       '

       1.9.1 문자열 Index 정하기 : Index 표기는 BASIC을 따른다.

       >> x(1)
       ans =
       a
       >> x(2:3) <- 파이썬과는 다르게 직관적으로 "2번째 문자부터 3번째 문자까지"를 의미한다.
       bc

      1.9.2 문자열 결합

      다음 방법으로 문자열을 결합하여 더 큰 문자열을 만들 수 있다.
                   new_string = [string1, string2, string3,  .... ]
     
      1.9.3 문자열 함수

       length(str) : 문자열의 길이
       strcmp(str1, str2) : 문자열이 같으면 1, 다르면 0을 출력한다.
       str2num(str) : 문자열을 숫자로 변환시켜준다.
       abs(str) : 문자열 각각의 ASCII code값을 행 벡터로 반환한다.
       ※ 주의점 : '123' + '321'을 하면 444가 아닌 [100, 100, 100]이 출력된다. 즉, abs값으로 계산된다.
       strrep(source, str1, str2) : source안의 str1을 모두 str2로 변환한다.



1.10 입력과 출력문

     1.10.1 매트랩에서의 세미콜론 : 결과를 출력하지 않는다.
     1.10.2 매트랩 프로그램 된 출력

      >> fprintf('This is a test.\n');
      This is a test.
      >> fprintf('The value of pi is %g.\n', pi);   <- 변수 값을 표현할 때는 %g를 쓴다.
      The value of pi is 3.14159.
      >> str1 = 'The value of pi is %g.\n';
      >> fprintf(str1, pi); <- ANSI C의 int printf("format", ...)를 따른다. 2번째 변수 부터는 가변 변수들임.

     1.10.3 매트랩 프로그램 된 입력

      숫자 입력 형식>
   
      xx = input('문자열');

      문자열 입력 형식>

      xx_string = input('문자열','s');

      ※ input 함수로 출력된 문자열은 새 줄을 만들지 않음을 주의한다.

     ※ 매트랩에서 %는 주석문을 의미한다.

1.11 매트랩에서 플롯 만들기

      이 절에서는 plot 함수를 이용하여 몇 개의 단순한 수학적 함수로 플롯을 만드는 빠른 방법을 제시한다.
      7장에서 Plotting을 더 깊이 배우도록 한다.
     
      ※ 참  고 : 배열용 기본 수학 연산자 : 곱셈 (.*) 나눗셈 (./) 지수(.^)
 
     Plot함수를 이용한 Plotting의 순서는 다음과 같다.

     1. 독립변수 x 만들기
     2. 함수 y 정의하기 ( 이때 배열용 기본 수학 연산자들을 사용한다. 독립변수 x가 단일 값이 아닌 벡터이기 때문이다.)
     3. (plot의 속성을 정해주는 함수들)
     4. plot(x, y)

      예) y = |x| sin(x) 그리기

      >> x = linspace(-100, 100, 5000);    % -100부터 100 사이의 값들을 5000개의 동일한 간격의 값들을 만들어 행벡터 x에 저장한다.
      >> y = abs(x) .* sin(x);        % 벡터 내 같은 위치에 있는 속성끼리의 곱셈을 한다. 결과 역시 행벡터.
      >> plot(x,y);

1.12 도움말 기능
       
      1.12.1 텍스트 버젼

      >> help
      >> help demos
      >> help 함수명
      >> help xpbombs % 지뢰찾기 게임
      >> help elfun % 기초 수학함수
     
      1.12.3 lookfor 명령 : 도움말 중 첫 줄을 조사하는 키워드 탐색 명령어.
     
      예)
      >> lookfor logarithm
      LOG            Natural logarithm.
      LOG10         Common (base 10) logarithm.
      LOGSPACE  Logarithmically spaced vector.
      LOGM          Matrix logarithm.
      BETALN       Logarithm of beta function.

      1.12.4 which  명령

      which 명령은 자신의 컴퓨터에서 m-파일을 찾아준다.
      m-파일이란 특별한 기능을 수행하도록 설계된 일련의 매트랩 명령어를 갖고 있는 문서 파일이다.

1.13 매트랩 스크립트 파일

      파이썬 스크립트 파일을 생각하면 된다. 즉 매트랩 프로그램이 인식할 수 있도록 path를 잡아주고,
      그 path안에서 m-파일(확장자 .m)의 이름만 입력하면 하나의 명령어처럼 바로 실행되는 것이다.

     



     



  

AND

ARTICLE CATEGORY

전체 (126)
EECS (56)
Algorithm (2)
C/C++/STL (6)
Python (3)
MATLAB (7)
Compiler (7)
Verilog (4)
PSPICE (1)
Circuit (5)
Linux (13)
Dos Shell (0)
Trouble Q&A (7)
Physics (5)
Misc. (60)

RECENT ARTICLE

RECENT COMMENT

RECENT TRACKBACK

CALENDAR

«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

ARCHIVE