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...
0 个评论
回答(1 个)
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);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!