Effacer les filtres
Effacer les filtres

Conditional entry-wise matrix operation

2 vues (au cours des 30 derniers jours)
Deepayan Bhadra
Deepayan Bhadra le 20 Fév 2018
Commenté : Deepayan Bhadra le 21 Fév 2018
Hi, I am trying to compute the matrix 'Y' as follows with matrix 'X' as an input.
If X_ij > 0
then Y_ij = X_ij + log(exp(-X_ij)+1)
else Y_ij = log(1+exp(X_ij))
How do I implement this without any loops? Thanks.

Réponse acceptée

James Tursa
James Tursa le 21 Fév 2018
Modifié(e) : James Tursa le 21 Fév 2018
Hints:
What does the expression -abs(X) do in relation to your condition of X_ij > 0? Could you use this in your formula for the calculation of Y?
Or, what if you created a logical indexing variable for your condition, such as g = X > 0. Can you think of how to use g as an index to calculating the appropriate elements of Y?
  1 commentaire
Deepayan Bhadra
Deepayan Bhadra le 21 Fév 2018
I got it, thanks to logical indexing!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by