Conditional entry-wise matrix operation

조회 수: 4 (최근 30일)
Deepayan Bhadra
Deepayan Bhadra 2018년 2월 20일
댓글: Deepayan Bhadra 2018년 2월 21일
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.

채택된 답변

James Tursa
James Tursa 2018년 2월 21일
편집: James Tursa 2018년 2월 21일
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
Deepayan Bhadra
Deepayan Bhadra 2018년 2월 21일
I got it, thanks to logical indexing!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by