math function for a vector

조회 수: 9 (최근 30일)
Eugene
Eugene 2016년 7월 8일
댓글: Eugene 2016년 7월 8일
I'm working with Matlab R2012a. I have a simple question and I know there must be a simple answer, but searching and playing around with the syntax hasn't worked.
function sig = sigmoid( x)
sig = 1/(1+exp(-x));
end
This function works in Octave as is, but in Matlab it only works with scalars. What is the syntax for this function when x is a vector or matrix and I need this applied element wise? I tried the "." notation to no avail. I know I can loop through all the elements of x, but is there a more elegant way?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 8일
편집: Azzi Abdelmalek 2016년 7월 8일
function sig = sigmoid( x)
sig = 1./(1+exp(-x));
  댓글 수: 1
Eugene
Eugene 2016년 7월 8일
Perfect, thank you! Not sure how I missed this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by