본문 바로가기

Matlab

M-file


 vsum.m


function s = vsum(a,b) % function 출력값 = 함수명(입력변수), 함수명 = 파일명

c= a-b;

s= a+b;


 >> d = vsum(1,2)

d =

     3


 plusmin.m


function [ p m] = plusmin(a,b)

p= a+b;

m = a-b;

end


 >> [a b ] = plusmin(5,3)

a =

     8

b =

     2


test.m

 function s=test() 

   global a; %전역변수 a를 함수로 

   s = a+1; 

   a = 3; 

end


 >> global a %전역변수 a선언

>> a = 1;

>> test

ans =

     2

>> a

a =

     3


'Matlab' 카테고리의 다른 글

Plot  (0) 2013.12.23
Control Flow  (0) 2013.12.23
Matrix Operator  (0) 2013.12.23
Matrix  (0) 2013.12.23
MATLAB 기호프로세서(symbolic processor) 기초2  (0) 2013.09.02