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

a = [2,3;5,6]
b = [2,5;6,9]
c = a + b
d = a .+ b

1 Comment

"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.

Sign in to comment.

Answers (1)

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.

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Release

R2024a

Asked:

on 29 Aug 2024

Edited:

on 29 Aug 2024

Community Treasure Hunt

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

Start Hunting!