problem with the sum function
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone, im trying to solve this exercise
but appear a error that i dont know how to solve
"Error using ^
Inputs must be a scalar and a square matrix.
To compute elementwise POWER, use POWER (.^) instead."
this is my code:
function [norma2] = normalizacao(X)
[n, m] = size(X);
for i = 1:n
for j = 1:m
norma2(i, j) = sqrt(sum(X(i, :)^2))
end
end
end
Someone can help me?
0 个评论
采纳的回答
更多回答(1 个)
Image Analyst
2020-7-2
You need to leave i as a variable because it did not say to sum over i. So just sum over the j dimension for a given i.
Try this:
norma2 = sqrt(sum(X(i, 1 : M) .^ 2));
No loops needed. Perhaps M is the number of columns, but it didn't say that explicitly so I'm just leaving it as M
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Install Products 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!