MATLAB Answers

hp
0

how to add a constant to all the elements of the matrix?

Asked by hp
on 1 May 2018
Latest activity Answered by Star Strider
on 1 May 2018
plz help, how to add or multiply a constant value to all the elements of the matrix...

  0 Comments

Sign in to comment.

1 Answer

Answer by Star Strider
on 1 May 2018

Since ‘implicit expansion’ arrived in R2016b, this will work:
A = rand(3);
B = A + 5;
or:
B = A * 5;
For all releases, using bsxfun will work:
B = bsxfun(@plus, A, 5);
or:
B = bsxfun(@times, A, 5);

  0 Comments

Sign in to comment.