Borrar filtros
Borrar filtros

Normalizing columns of a matrix

5 visualizaciones (últimos 30 días)
Muzammil Behzad
Muzammil Behzad el 22 de Abr. de 2016
Respondida: Julia Gala el 4 de Dic. de 2017
Hello everyone,
I have a matrix of, let's say 10000x10000 size, and I want to normalize each column of the matrix by its respective norm (let's say ith column divided norm of ith column) and also store the respective norms in another vector (so there'll be a vector of size 10000x1 where each row will correspond to norm of respective column). This is of course achievable by using a for loop but I need to know if there's any optimum way or a function that would do it for me quickly.
Thanks.

Respuesta aceptada

Roger Stafford
Roger Stafford el 22 de Abr. de 2016
Assume by "norm" you mean the usual 2-norm, and that your 10000 x 10000 matrix is named 'M'.
n = sqrt(sum(M.^2,1)); % Compute norms of columns
M = bsxfun(@rdivide,M,n); % Normalize M
n = reshape(n,[],1); % Store column vector of norms
  1 comentario
Muzammil Behzad
Muzammil Behzad el 22 de Abr. de 2016
Thanks a lot to both of you. It worked! :)

Iniciar sesión para comentar.

Más respuestas (1)

Julia Gala
Julia Gala el 4 de Dic. de 2017

Categorías

Más información sobre Resizing and Reshaping Matrices 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