MATLABマニュアル(2003)ver5 - Kawamata る.後者のm-ファイルを用いた方法はC や他のプログラム言語と同じようなものである. ここでは,コマンドラインからの入力について説明する.MATLAB を起動すると“”という記号が 表示される.以降,この記号のことを

  • Published on
    10-May-2018

  • View
    220

  • Download
    2

Embed Size (px)

Transcript

  • 1

    MATLAB 2003

    ( )

    WEB

    http://www.mk.ecei.tohoku.ac.jp/dsptext/

    1. MATLAB

    2.

    3.

    4. m-

    5.

    6.

    7. MATLAB

    8.

    9. 10. Octave(MATLAB)

    MATLAB

    MATLAB Matrix Laboratory

    MATLAB

    MATLAB matlab MATLAB % matlab

    MATLAB MATLAB exit quit >>exit

    MATLAB m-

  • 2

    m- C MATLAB >>>>

    10+20/2-5*3 /* >>10+20/2-5*3

    return(enter) ans =

    5

    return(enter) ( ) >>(10*(5-3))/2

    ans =

    10

    >>x=3

    "=" x =

    3

    x 3 >>x=3;

    ";" >>x+3

    ans =

    6

    >>x=4;

    >>x+3

  • 3

    ans =

    7

    1 2 ()(Ctrl ) p(n)

    >>x

    x =

    4

    MATLAB x X >>who

    clear x

    >>clear x

    MATLAB >>sqrt(9)

    ans =

    3

    >>sin(pi/6)

    ans =

    0.5000

    MATLAB pi >>log10(5)

  • 4

    ans =

    0.9660

    ( ) help sin >>help sin

    MATLAB i j MATLAB 1i

    >> (3+1i)*(2-3i)

    ans =

    9.0000-7.0000i

    conj(x) x

    MATLAB MATLAB m n m,n 1 n 1 n [1 3 5 7 9 11] MATLAB >>A=[1 3 5 7 9 11]

    A =

    1 3 5 7 9 11

    A[ ] A 3 >>A(3)

    ans =

    5

    A >>size(A)

  • 5

    ans =

    1 6

    16 A 1 6

    A 3 >>A(3)=4;

    1 C 02 1 >>A=[1 3 5 7 9];

    >>B=[2 4 6 8 10];

    >>A+B

    ans =

    3 7 11 15 19

    >>B-A

    ans =

    1 1 1 1 1

    >>B.*A

    ans =

    2 12 30 56 90

    >>A./B

    ans =

    0.5000 0.7500 0.8333 0.8750 0.9000

    */.*./ sqrt >>sqrt(A)

    ans =

    1.0000 1.7321 2.2361 2.6458 3.0000

  • 6

    x 0, 0.1, 0.2, ..., 3.0, 3.1 sin(x) x 0.1 0 3.1":" >>x=0:0.1:3.1;

    x 0 0.1 3.1 32 1 : :

    2:5 1 >>z=2:5

    z =

    2 3 4 5

    10:-1:5 x sin(x)

    >>sin(x)

    32 x 32 sin(x)

    3 3 >>A=[1 2 3;4 5 6;7 8 9]

    A =

    1 2 3

    4 5 6

    7 8 9

    ";" m n m, n A+B, A-B, A.*B, A./B

    >>A(3,2)

    3 4 >>size(A)

    >>A=[1 2 3;4 5 6;7 8 9];

    >>sqrt(A)

  • 7

    ans =

    1.0000 1.4142 1.7321

    2.0000 2.2361 2.4495

    2.6458 2.8284 3.0000

    ones zeros >>ones(3,4)*2

    ans =

    2 2 2 2

    2 2 2 2

    2 2 2 2

    2 2 2 2

    2 >>A(2,:)

    3 >>A(:,3)

    "'" >>A'

    ans =

    1 4 7

    2 5 8

    3 6 9

    "*""C*D" C n D n >>C=[1 2;3 4];

    >>D=[1 2 3;4 5 6];

    >>C*D

    ans =

    9 12 15

    19 26 33

  • 8

    m-

    MATLAB m-m-m-

    m-

    UNIX Mule 2

    v1=[3 5]; % 1

    v2=[-6 2]; % 2

    v1*v2' % 1 2

    3 m naiseki.m MATLAB m- UNIX MS-DOSWindows

    >>cd

    >>cd m-

    m-

    >>naiseki

    ans =

    -8

    1 2 v1 v2 %% 3 v2 1 2 2 1 ' 3 ;

    MATLAB

  • 9

    sin m- x=0:0.1:3.1;

    plot(sin(x))

    m-m-,figure sin x 1 x 1 0 sin(x) 2 x 2 0.1 sin(x) x plot(sin(x))

    plot(x,sin(x))

    1 2 x 32 MATLAB

    MATLAB m- x=0:0.1:3.1;

    y1=sin(x); %

    y2=cos(x); %

    hold on %

    plot(x,y1)

    stem(x,y2)

    axis([0 3.1 -1.2 1.2]),grid %

    xlabel('x'),ylabel('y1,y2') %

    hold off

    sin cos

    >>clf

    clf figure hold on stem plot axis axis([

    ]) axis grid","","1 grid xlabel,ylabelxlabel('Time')

  • 10

    >>print

    MATLAB conv

    2 [3 4 -1][3 1 6 2] y y(1)=33 = 9

    y(2)=31 + 43 = 15

    y(3)=36 + 41 + (-1)3 = 19

    y(4)=32 + 46 + (-1)1 = 29

    y(5)= 42 + (-1)6 = 2

    y(6)= (-1)2 = -2 A=[3 4 -1];

    B=[3 1 6 2];

    y=conv(A,B)

    ans =

    9 15 19 29 2 -2

    filter

    X y

    A(1)y(n) = -A(2)y(n-1)-A(3)y(n-2)- ... -A(na+1)y(n-na)

    +B(1)x(n)+B(2)x(n-1)+B(3)x(n-2)+ ... +B(nb+1)x(n-nb)

    A=[1 -0.5];

  • 11

    B=[0.5];

    x=[1 zeros(1,10)];

    y=filter(B,A,x)

    y =

    Columns 1 through 7

    0.5000 0.2500 0.1250 0.0625 0.0313 0.0156 0.0078

    Columns 8 through 11

    0.0039 0.0020 0.0010 0.0005

    freqz

    filter

    A=[1 -0.5];

    B=[0.5];

    W=-pi:0.01:pi;

    H=freqz(B,A,W);

    magH=abs(H);

    plot(W,magH);

    H abs

    MATLAB

    ("MATLAB ")

    pi

    eps

    +

  • 12

    -

    *

    /

    .*

    ./

    ^

    .^

    ==

    ~=

    , =

    & |

    ~

    : 1:5 , 4:2:20

    ;

    ...

    %

    .' A.'

    abs abs(x)x

    angle angle(h) h

    axis axis([XMIN XMAX YMIN YMAX]) x y bilinear [NUMd,DENd]=bilinear(NUM,DEN,Fs) z blackman blackman(N)Blackman N boxcar boxcar(N) 1 butter [B,A]=butter(N,Wn)N Butterworth buttord buttord(Wp,Ws,Rp,Rs) Wp Rp [dB] Ws

    Rs [dB] Butterworth N

    ceil ceil(x)x x

    circconv circconv(h,x) h x

    colormap colormap(gray)figure colormap([0 0 0])

    compose compose(f,g,x,z)Symbolic Math Toolbox f(x) x g(z)

    conv c=conv(a,b) a b

  • 13

    conv2 C=conv2(A, B) A B 2 cos cos(x)x

    cot cot(x)x

    direct

    disp disp(X) X X double double(x)x

    error error('message')

    exp exp(x)x

    fft fft(x) x

    fft2 fft2(X) X 2 fftshift fftshift(x) x

    figure figure figure filter y=filter(b,a,x) X

    filter2 Y=filter2(B,X) B 2 FIR X

    fir1 fir1(N,Wn)N FIR fix fix(x)x

    flipud flipud(X) X floor floor(x)x x

    for for end

    freqs freqs(b,a,w) b a

    freqz freqz(b,a,w)

    freqz2 freqz2(X)2 freqztrans freqztrans(b,a,ftype,thetac,wc)Symbolic Math Toolbox function

    gray gray

    grid grid: hamming hamming(N)Hamming N hanning hanning(N)Hanning N hold hold on

    if

    ifft ifft(x)x

    imag imag(x) x

    imnoise J=imnoise(I,TYPE,...) I

    impinvar impinvar(B,A,Fs) B A

    BZ,AZ

    imread A=imread(FILENAME,FMT)FILENAME A

    imresize imresize(A,s) A s

    imshow imshow(I,[LOW HIGH]) I

  • 14

    iztrans iztrans(f)Symbolic Math Toolbox f z kaiser kaiser(N,beta)beta Kaiser N

    legend legend(string1,string2,string3, ...) figure

    length length(x) x

    linspace linspace(x1,x2,n)x1 x2 n

    log10 log10(x)x 10

    log2 log2(x)x 2

    max max(x)x

    mesh mesh(X,Y,Z)

    meshgrid meshgrid(x,y) y( x) 2 x y

    min min(x)x

    mod mod(x,y)x y myconv myconv(h,x) h x

    MATLAB conv mydft mydft(x) x

    myfft myfft(x) x

    myfilter myfilter(b,a,x)MATLAB filter numden numden(A)Symbolic Math Toolbox A

    ones ones(m,n) 1 m n pcolor pcolor(X,Y,Z)3 plot plot(x,y)xy

    plot(x,y,'o')

    plot3 plot(x,y,z)3 poly2sym poly2sym(b,z)Symbolic Math Toolbox b

    z

    prod prod(X)XX

    real real(x)x

    roots roots(C) C

    shading shading interp

    simple simple(s)Symbolic Math Toolbox s simplify smplify(S)Symbolic Math Toolbox S

    sin sin(x)x

    sinc sinc(x)x sinc

  • 15

    y = sin(pi*x)/(pi*x) x ~= 0

    = 1 x == 0

    size size(X) X

    sqrt sqrt(x)x

    stem stem(x,y)xy

    subplot subplot(m,n,p):figure m n p

    surfl surfl(X,Y,Z)3 switch case

    sym2poly sym2poly(A)Symbolic Math Toolbox A

    syms Symbolic Math Toolbox symsum symsum(s,a,b)Symbolic Math Toolbox s a b

    tan tan(x)x

    tf2sos tf2sos(B,A) AB 2

    unwrap unwrap(P) P2 view view(AZ,EL)3 AZEL

    while while end

    xlabel xlabel('text') x

    ylabel ylabel('text') y

    zeros zeros(m,n)m n

    zlabel zlabel('text') z

    zp2tf zp2tf(Z,P,K) Z P K

    zplane zplane(Z,p) Z p

    ztrans ztrans(f,k,w)Symbolic Math Toolbox k f z

    MATLAB 2000 R. Vaillancourt MATLAB1997 MATLAB CG1995 MATLAB 1998

  • 16

    MathWorks https://jp.mathworks.com/

    OctaveMATLAB

    Octave MATLAB MATLAB

    Octave MATLAB

    MATLAB toolbox

    Octave

    Octave

    Octave http://www.mk.ecei.tohoku.ac.jp/dsptext/octave/ Octave (): http://www.gnu.org/software/octave/

    MATLAB Octave 2002 MATLAB CG1995 MATLAB 2001 Linux Tools for Numerical Computation on Linux

Recommended

View more >