Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Nx3 矩阵 (A),列分别是 X、Y、Z。我想为每一行计算 sqrt(X^2+Y^2+Z^2) 的范数。我为此做了一个for循环:
for i = 1:length(A) Result(i) = norm(A(i,:)) end
有没有其他方法可以避免for循环?
谢谢
你可以这样做:
sqrt(sum(A.^2, 2))
您的方法返回一个 1x3,这将返回一个 3x1。因此,如果您愿意,可以转置它,但我怀疑您是否真的需要。