normalize a maatrix of 13 columns
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello
I have a matrix say A of 13 columns where each column represents a waveform. I am supposed to normalise each column of the matrix. I want to square each element of the matrix and carry out a summation of the elements in each column separately such that i have 13 values at the end. I want to take a squareroot of these 13 elements and then divide each column of the matrix A by the 13 elements. such that the first column of A is divided by the first element and so on. It would be very helpful if anyone can help me with this
0 Kommentare
Akzeptierte Antwort
Friedrich
am 13 Aug. 2012
Hi,
I think this should do it:
bsxfun(@rdivide,A,sqrt(sum(A.*A,1)))
So looking at an easy example:
A = [1 2 3; 4 5 6]
bsxfun(@rdivide,A,sqrt(sum(A.*A,1)))
You will see its fine:
>> A = [1 2 3; 4 5 6]
bsxfun(@rdivide,A,sqrt(sum(A.*A,1)))
A =
1 2 3
4 5 6
ans =
0.2425 0.3714 0.4472
0.9701 0.9285 0.8944
>> 1/sqrt(4^2+1^2)
ans =
0.2425
>> 4/sqrt(4^2+1^2)
ans =
0.9701
>>
0 Kommentare
Weitere Antworten (2)
Wayne King
am 13 Aug. 2012
Bearbeitet: Wayne King
am 13 Aug. 2012
You can just use
normc()
A = randn(1000,13);
B = normc(A);
If you happen to have the Neural Network Toolbox.
If you want to carry it out as you described.
A = randn(1000,13);
norm2 = sum(abs(A).^2,1);
norm2 = sqrt(norm2);
for nn = 1:size(A,2)
B(:,nn) = A(:,nn)./norm2(nn);
end
0 Kommentare
Matt Kindig
am 13 Aug. 2012
Hi Kim,
Let's go through each step:
To square, use A^.2
To sum, use the sum() function. Read the documentation to learn about the dimension (DIM) argument to sum().
To square root, use the sqrt() function.
To normalize, you will need the element divide operator ./. You will also need the repmat() function.
Look at the documentation for these functions, and I'm sure you will be able to piece it together yourself.
Let us know if you have any further troubles, once you've looked over the documentation.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!