Effacer les filtres
Effacer les filtres

Creating a function with a logical output.

21 vues (au cours des 30 derniers jours)
Craig
Craig le 14 Fév 2013
Hi all,
I am quite confused. I have a function say like this:
function [output] = TLU( inputs, weights, threshold )
activationMagnitude = sum(weights.*inputs)
if activationMagnitude > threshold
output = true;
else
output = false;
end
But when I use class(ans) it always shows a char data type - despite me specifying the output as either true or false!
Why is this?
Best regards,
Craig

Réponse acceptée

Thorsten
Thorsten le 14 Fév 2013
Modifié(e) : Thorsten le 14 Fév 2013
There's nothing wrong with your function, you can just do it more concisely
function output = TLU( inputs, weights, threshold )
output = sum(weights.*inputs) > threshold;
Then
y = TLU([1 2 3], [ 4 5 6 ], 100)
yields
y =
0
And
class(y)
yields
ans =
logical
But of course then class(ans) gives char (because ans is the string 'logical'), but this has nothing to do with the class returned by your function.

Plus de réponses (1)

José-Luis
José-Luis le 14 Fév 2013
It does return logical for me.
What does
class(TLU(rand, rand, rand))
return? If ans returns something different, you may have overwritten its value before you call to class()
  1 commentaire
Azzi Abdelmalek
Azzi Abdelmalek le 14 Fév 2013
Modifié(e) : Azzi Abdelmalek le 14 Fév 2013
The question is what ans represent?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Graphics Object Programming dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by