Clear Filters
Clear Filters

Summing squared elements of a column of a matrix

42 views (last 30 days)
for i=1:N
s(i)=sum(V(:,2))/sqrt(n);
t(i)=sum(V(:,2))/sqrt(sum((V(:,i).*V(:,i)));
end
Both s and t are Nx1 vectors, while V is a nxN matrix. In s I summed the elements of each column of V for every element of s. How can I divide, in t, by the square root of the sum of the SQUARED elements of each column of V?

Answers (1)

Star Strider
Star Strider on 6 Aug 2019
It’s not clear what you want to do.
Try this:
V = rand(6,5); % Guess What ‘V’ Is
n = size(V,1);
N = size(V,2);
s = sum(V)/sqrt(n); % Sum Over Columns, Divide By ‘sqrt(n)’
t = sum(V)./sqrt(sum(V.^2,2)); % Sum Over Columns, Divide By ‘sum(sqrt(Rows))’

Community Treasure Hunt

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

Start Hunting!