How can I fix this problem
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
the cyclist
il 29 Mag 2017
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 Commenti
the cyclist
il 30 Mag 2017
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));
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!