简体   繁体   中英

Converting code from Matlab to R: ./ operator

I am converting Matlab code into R. In one case, there is a statement involving matrix sigma . How can I translate that Matlab line into R syntax?

diag(1./sigma)

I know it gets the diagonal, but don't know what the 1./ is. My vague guess would be 1/sigma . Is this correct?

  • 1/Sigma is the invert of the matrix Sigma
  • 1./Sigma is a matrix formed by the invert of Sigma elements

In matlab, .* and ./ are used to do element by element operations instead of cross multiplication. So in this case, you should just use 1/sigma and make sure your R matrix after conversion iis one divided by each element in the original matrix.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM