将范数函数应用于矩阵的行-Matlab [英] applying norm function to rows of matrix - Matlab

查看:97
本文介绍了将范数函数应用于矩阵的行-Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3列n行矩阵:

[ a,b,c;
  d,e,f;
  g,h,i; ]

我想将norm函数应用于每一行,并得到一个包含规范的1xn矩阵:

I want to apply the norm function to each of the rows, and get a 1xn matrix containing the norms:

[ norm([a,b,c]);
  norm([d,e,f]);
  norm([g,h,i]); ]

我可以使用for循环来执行此操作,但是有更好的方法吗?

I could do this with a for-loop, but is there a better way?

推荐答案

 norms = sqrt(sum(A.^2,1))

 norms = sqrt(sum(A.^2,2))?

取决于您的坐标是行还是列.

depending on whether your coordinates are in rows or in columns.

这篇关于将范数函数应用于矩阵的行-Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆