如何将矩阵的每一行除以固定行? [英] How can I divide each row of a matrix by a fixed row?
本文介绍了如何将矩阵的每一行除以固定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个像这样的矩阵:
Suppose I have a matrix like:
100 200 300 400 500 600
1 2 3 4 5 6
10 20 30 40 50 60
...
我希望将每一行除以第二行(每个元素除以相应的元素),所以我得到:
I wish to divide each row by the second row (each element by the corresponding element), so I'll get:
100 100 100 100 100 100
1 1 1 1 1 1
10 10 10 10 10 10
...
我能做到吗(无需编写显式循环)?
Hw can I do it (without writing an explicit loop)?
推荐答案
使用bsxfun
:
outMat = bsxfun (@rdivide, inMat, inMat(2,:));
bsxfun
的第一个参数是您要应用的函数的句柄,在本例中为右分隔.
The 1st argument to bsxfun
is a handle to the function you want to apply, in this case right-division.
这篇关于如何将矩阵的每一行除以固定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文