Matlab’s Element-wise Operators

May 17, 2011

Have you ever wanted to multiply or divide the values of two corresponding cells between arrays?  Ever wanted to write one line of code instead of a for-loop? Well now you can.

Matlab has special operators to perform multiplication, division and powers between the corresponding cells of two matrices. These operators are useful for simplifying and optimizing code that requires larger matrices. They can replace for loops and using them instead of for-loops saves time.


.* - Multiplication
./ - Division
.^ - Power

Example:

 

If A =

2 5
-3 7

& B =

6 1
3 2

 

Then A.*B =

12 5
-9 14

 

More Examples

Tags: ,

2 Responses to Matlab’s Element-wise Operators

  1. yaghob ghasemi on May 24, 2011 at 2:08 am

    very good

  2. Basic Matlab Code Optimization | Kyle Barnoff on October 22, 2011 at 11:07 am

    [...] Matlab’s Element-wise Operators [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*