Vector addition with 2-dim array
1 次查看(过去 30 天)
显示 更早的评论
A is an R by C (R x C) array and I have a rows vector V with length C. I want to add or subtract V from every rows in the array A.
Is there any way to simplify this procedure?
Of course I know some method like:
VV = V(onese(1:R), :)
result = A +/- VV;
but I just wanted an one-line command or operator, like:
result = A ※ V
result = somefunction(A, V);
I need to find ※ or somefunction()
1 个评论
Jan
2013-3-21
ones(1:R) creates a matrix with R dimensions and prod(1:R) elements. You mean ones(1, R).
The one-line command might have the advantage, that the matrix VV is not created explicitly:
result = A - v(ones(R,1), :);
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!