[Quick Question]Multiplications of all elements
1 次查看(过去 30 天)
显示 更早的评论
Hi guys,
I have a matrix A = [ 1;9;1;4;4;6]
Is there any efficient way other than writing a loop that reach the result,
B = 1*9*1*4*4*6 = 864
Thanks a lot
==== Problem solved. Those comments are really useful!
0 个评论
采纳的回答
per isakson
2012-8-18
Yes. Try
B = prod( A )
B =
864
6 个评论
Oleg Komarov
2012-8-18
@Xiao: the documentation of prod() references cumprod(). You better give a try to the documentation, since it will definitely save you time.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!