Multiply a scalar to all column of a table

150 visualizaciones (últimos 30 días)
Deepa Maheshvare
Deepa Maheshvare el 3 de Feb. de 2020
Comentada: Steven Lord el 26 de Mzo. de 2020
I've a table, T. I want to mulitply a scalar to all values in the table (similary to scalar multiplication of a matrix e.g. 2*rand(5,5)).
I tried 10*T, it doesn't work.
Any suggestions?

Respuesta aceptada

Bhaskar R
Bhaskar R el 3 de Feb. de 2020
Editada: Bhaskar R el 3 de Feb. de 2020
Suppose T is your table variable with it's variable name Var1
T.Var1 = 10*T.Var1;
  4 comentarios
JZ
JZ el 26 de Mzo. de 2020
I believe can also use T{:, :} = T{:, :} .* 10
Steven Lord
Steven Lord el 26 de Mzo. de 2020
If all the variables in your table can be concatenated together:
T.Variables = 10*T.Variables;
If they can't, you can use varfun with the 'InputVariables' parameter set to something like @isnumeric to operate only on the variables that are numeric (and so for which it makes sense to multiply by a number.)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by