I have a 5x10 matrix of non-zero values. How can I normalise the 9'th column and make all its values equal to 1.

답변 (1개)

Cris LaPierre
Cris LaPierre 2020년 12월 6일

0 개 추천

Normalize and making all its values equal 1 are two different, non-equivalent processes.
Assuming you want to set all values to 1, something like this should work:
% Create 5x10 matrix
m=rand(5,10);
% Set all values in the 9th column equal to 1
m(:,9)=1
m = 5×10
0.0140 0.6808 0.8513 0.3171 0.7192 0.0997 0.3669 0.9666 1.0000 0.3060 0.6399 0.8033 0.3665 0.9091 0.0736 0.3212 0.0721 0.8504 1.0000 0.0836 0.9530 0.8310 0.2890 0.7311 0.5017 0.7145 0.7677 0.2626 1.0000 0.5972 0.9194 0.2587 0.6253 0.5791 0.0637 0.3085 0.7832 0.5275 1.0000 0.9422 0.1942 0.1323 0.8923 0.1072 0.5695 0.4803 0.0237 0.6503 1.0000 0.3719

댓글 수: 2

Fadi Lama
Fadi Lama 2020년 12월 6일
I want to normalize the column so that all its values are equal to one if that makes sense
(I was thinking of dividing each row by the value in the 9th column but was looking for something simpler)
Ok, but the effect would be the same, right?
Divide column 9 by itself.
% Create 5x10 matrix
m=rand(5,10);
% Normalize each value in column 9 by dividing by itself
m(:,9)=m(:,9)./m(:,9)
m = 5×10
0.2220 0.3633 0.2327 0.0752 0.2392 0.0317 0.2442 0.3519 1.0000 0.7160 0.5693 0.1504 0.6034 0.5271 0.7093 0.1267 0.3073 0.8678 1.0000 0.9064 0.7947 0.9117 0.4383 0.6368 0.9732 0.0727 0.4674 0.7977 1.0000 0.9629 0.0800 0.7259 0.5368 0.5817 0.3788 0.1339 0.5561 0.0655 1.0000 0.4742 0.3518 0.1036 0.2013 0.5821 0.3154 0.0541 0.5438 0.1723 1.0000 0.4470
btw, normalizing each row by the value that is in its column 9 is just as easy
m2=rand(5,10);
m2=m2./m2(:,9)
m2 = 5×10
0.9815 0.2271 0.2902 0.1020 0.5926 1.0735 0.3889 0.0205 1.0000 0.4472 0.7600 0.5928 0.8442 1.0917 1.2915 0.7797 0.7137 0.8735 1.0000 0.3898 16.0345 13.7806 6.8526 20.2673 1.9944 13.3427 14.5061 5.6493 1.0000 4.1880 0.0475 0.7783 0.9273 1.0538 1.0699 0.7781 0.6793 0.4814 1.0000 1.1109 0.2156 0.8290 0.1595 0.7077 0.0473 0.7178 0.6384 0.3150 1.0000 1.0240

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

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2020년 12월 6일

댓글:

2020년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by