필터 지우기
필터 지우기

Normalizing columns of a matrix

조회 수: 8 (최근 30일)
Muzammil Behzad
Muzammil Behzad 2016년 4월 22일
답변: Julia Gala 2017년 12월 4일
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.

채택된 답변

Roger Stafford
Roger Stafford 2016년 4월 22일
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
Muzammil Behzad
Muzammil Behzad 2016년 4월 22일
Thanks a lot to both of you. It worked! :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Julia Gala
Julia Gala 2017년 12월 4일

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by