Divide each column by the sum of the column in a matrix
8 次查看(过去 30 天)
显示 更早的评论
I am sure this is an elementary question, but I could not find the answer when searching the Matlab website. I was wondering how to divide each column in a matrix by the sum of that column and do the same process for all the columns in a matrix. The result should then be returned as a new matrix.
As an example take the following matrix
D = [-0.442898926677253 -0.165258150390309 0.850111606631490 -0.801783725737275;
-0.505610279127129 0.455832504673115 -0.205467096352270 4.76435784320108e-15;
-0.540885414880185 -0.746406858955920 -0.439177413926944 0.534522483824847;
-0.505610279127129 0.455832504673115 -0.205467096352275 0.267261241912423];
Now, for the first column;
U(:,1)/sum(U(:,1))
gets the first column of D divided by the sum of the column, but how do I do this for all of the columns and return the output as a new matrix?
2 个评论
Matt J
2022-5-19
U(:,1)/sum(U(:,1)) gets the first column of D divided by the sum of the column
No, it does that for U, not D.
采纳的回答
Matt J
2022-5-19
D./sum(D)
6 个评论
Torsten
2022-5-19
Just display D and look at the respective columns. You should be able to find the reason by inspection.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!