math function for a vector

8 Ansichten (letzte 30 Tage)
Eugene
Eugene am 8 Jul. 2016
Kommentiert: Eugene am 8 Jul. 2016
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?

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 8 Jul. 2016
Bearbeitet: Azzi Abdelmalek am 8 Jul. 2016
function sig = sigmoid( x)
sig = 1./(1+exp(-x));
  1 Kommentar
Eugene
Eugene am 8 Jul. 2016
Perfect, thank you! Not sure how I missed this.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by