Summing squared elements of a column of a matrix

24 次查看(过去 30 天)
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?

回答(1 个)

Star Strider
Star Strider 2019-8-6
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))’

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by