Borrar filtros
Borrar filtros

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

272 visualizaciones (últimos 30 días)
hp
hp el 1 de Mayo de 2018
Respondida: Star Strider el 1 de Mayo de 2018
plz help, how to add or multiply a constant value to all the elements of the matrix...

Respuestas (1)

Star Strider
Star Strider el 1 de Mayo de 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);

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by