How can I fix this problem
2 ビュー (過去 30 日間)
古いコメントを表示
I am trying to get a normalized matrix.
A=[1 1 2 4 7 1;0 2 2 1 3 9;
1 2 1 1 1 9;1 3 0 1 4 1];
R=size (A,1); % Row
C=size (A,2); % Column
for i=1:C
N=A(:,i)/sqrt(sum(A(:,i).^2));
S(i,:)=N
end
I do not get a right rows, then I tried a transpose and it does not work "nothing change".
0 件のコメント
回答 (1 件)
the cyclist
2017 年 5 月 29 日
When you say "normalized", what specifically do you mean?
The way you did it, your result is such that
sum(S.^2,2)
is a column vector of 1's, which is a form of normalization.
3 件のコメント
the cyclist
2017 年 5 月 30 日
Well, the rows of S have the correct normalization. You are overwriting N during each iteration of the for loop. So, this would have worked:
A=[1 1 2 4 7 1;0 2 2 1 3 9;
1 2 1 1 1 9;1 3 0 1 4 1];
R=size (A,1); % Row
C=size (A,2); % Column
for i=1:C
N(:,i)=A(:,i)/sqrt(sum(A(:,i).^2));
S(i,:)=N(:,i)
end
You can also avoid the for loop completely:
A=[1 1 2 4 7 1;0 2 2 1 3 9;
1 2 1 1 1 9;1 3 0 1 4 1];
N = A./sqrt(sum(A.^2));
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!