반전공자

Octave (함수 정의, 사용하는 방법) 본문

데이터분석/데테_인공지능

Octave (함수 정의, 사용하는 방법)

하연01 2021. 6. 5. 06:47

 

hello world 출력 함수

>> function printHelloWorld
printf("hello world\n")
endfunction
>> printHelloWorld
hello world
>> printHelloWorld()
hello world

 

[ 함수의 return value를 지정하는 방법 ]

 

hello world를 return 하는 함수 

>> function str = getHWStr()
str = "Hello World\n"
endfunction
>> printf(getHWStr())
str = Hello World

Hello World

 

 

 

[ 함수의 parameter를 지정하는 방법 ]

>> function str = concatStr(str1, str2)
str = strcat(str1, str2)
endfunction
>> printf(concatStr("hello", "world\n"))
str = helloworld

helloworld