What is the difference between + and .+ explain with example. Suppose i am adding two matrices which is best and what are their roles.

19 次查看(过去 30 天)
a = [2,3;5,6]
b = [2,5;6,9]
c = a + b
d = a .+ b
  1 个评论
Stephen23
Stephen23 2024-8-29
编辑:Stephen23 2024-8-29
"What is the difference between + and .+ explain with example."
The difference is very simple:
  • + is a MATLAB operator (shorthand for the PLUS function),
  • .+ does not exist.
"Suppose i am adding two matrices which is best and what are their roles."
Using the operator that actually exists is more likely to succeed.

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2024-8-29
Theree is no ‘.+’ (or ‘.-’) operator. (Using them would throw an error.) The dot operator with multiplication (‘.*’), division (‘./’), and exponentiation (‘.^’) are element-wise (array) operators, as opposed to matrix operators. Seee the documentation section on Array vs. Matrix Operations for details. Addition and subtraction are always element-wise operations.

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by