MATLAB Answers

Operate on all the columns of a matrix

1 view (last 30 days)
Zeynab Mousavikhamene
Zeynab Mousavikhamene on 30 Apr 2020
Answered: Sindar on 30 Apr 2020
I have a 100*3 matrix and want to normalize each column. Sth like this:
for i=1:3
norm=normalize(mat(:,i))
end
Is there any shorter way to remove "for loop"? This matrix is part of a code that changes its columns in each simulation.

  0 Comments

Sign in to comment.

Accepted Answer

Sindar
Sindar on 30 Apr 2020
"N = normalize(A,dim) returns the z-score along dimension dim. For example, normalize(A,2) normalizes each row."
norm_mat=normalize(mat,1);
norm is a function, so I don't recommend using it as a variable name

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by