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

272 次查看(过去 30 天)
plz help, how to add or multiply a constant value to all the elements of the matrix...

回答(1 个)

Star Strider
Star Strider 2018-5-1
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);

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by