Main Content

cumprod

累积产品

Description

例子

b= cumprod(一个返回the cumulative product of一个starting at the beginning of the first array dimension in一个whose size does not equal 1.

  • 如果一个是一个向量,然后acprod(a)返回包含元素元素元素的矢量一个

  • 如果一个是a matrix, thenacprod(a)返回包含每一列累积产品的矩阵s manbetx 845一个

  • 如果一个是a multidimensional array, thenacprod(a)沿着first nonsingleton dimension

例子

b= cumprod(一个,,,,暗淡返回the cumulative product along dimension暗淡。For example, if一个是a matrix, thenacprod(a,2)返回the cumulative product of each row.

例子

b= cumprod(___,,,,方向可选地使用任何先前的语法指定方向。您必须指定一个,并且可以选择地指定暗淡。例如,cumprod(A,2,'reverse')返回在行之内的累积产品一个通过从第二维的末端到开始。

例子

b= cumprod(___,,,,Nanflagspecifies whether to include or omit来自任何先前语法的计算值。cumprod(a,'includeenan')包括计算中的值cumprod(a,'omitnan')忽略它们。

Examples

全部收缩

1to5。这elementb(2)是the product ofA(1)A2),,,,whileb(5)是the product of elementsA(1)throughA(5)

a = 1:5;b = cumprod(a)
b=1×512 6 24 120

Define a 3-by-3 matrix whose elements correspond to their linear indices.

a =[1 4 7; 2 5 8; 3 6 9]
a =3×314 7 2 5 8 3 6 9

Find the cumulative product of the columns of一个。这elementb(5)是the product ofA(4)A(5),,,,whileB(9)是the product ofA(7),,,,A(8), 和A(9)

b = cumprod(a)
b=3×314 7 2 20 56 6 120 504

定义一个2 x-3矩阵,其元素对应于线性索引。

a = [1 3 5;2 4 6]
a =2×31 3 5 2 4 6

找到行的累积产物一个。这elementb(3)是the product ofA(1)A(3),,,,whileb(5)是the product ofA(1),,,,A(3), 和A(5)

b = cumprod(一个,,,,2)
b=2×31 3 15 2 8 48

创建一系列逻辑值。

a =[true false true; true true false]
a =2x3逻辑数组10 1 1 1 0

找到行的累积产物一个

b = cumprod(一个,,,,2)
b=2×31 0 0 1 1 0

这output has typedouble

(b)类
ans ='double'

在1到10之间创建一个随机整数的3 x-3矩阵。

RNGdefault; A = randi([1,10],3)
a =3×39 10 3 10 7 6 2 1 10

沿列计算累积产品。指定'撤销'在每一列中从底部到顶部工作的选项。结果的大小与一个

b = cumprod(一个,,,,'撤销'
b=3×3180 70 180 20 7 60 2 1 10

创建一个载体值并计算累积产品。s manbetx 845默认,cumprod包括值。当您包括时计算中的值,累积产物变为as soon as the first价值一个是encountered.

a = [1 3 nan 2 4 nan];b = cumprod(a)
b=1×613 NaN NaN NaN NaN

Ignore使用累积产品计算中的值'omitnan'option.

b = cumprod(一个,,,,'omitnan'
b=1×613 3 6 24 24

输入参数

全部收缩

输入阵列,指定为向量,矩阵或多维数组。

Data Types:double|single|int8|int16|int32|int64|uint8|uint16|uint32|uint64|逻辑
复杂的数字支持:万博1manbetxYes

沿着操作的维度,指定为正整数标量。如果未指定尺寸,则默认值是大于1的大小的第一个数组维度。

Consider a two-dimensional input array,一个

  • acprod(a,1)在列的连续元素上工作一个并返回每一列的累积产品。s manbetx 845

  • acprod(a,2)在行的连续元素上工作一个和返回the cumulative products of each row.

cumprod返回一个如果暗淡大于ndims(A)

累积方向,指定为'向前'(默认)或'撤销'

  • '向前'来自1to结尾of the active dimension.

  • '撤销'来自结尾to1of the active dimension.

条件,指定为以下值之一:

  • 'includeenan'-Includevalues from the input when computing each product, resulting invalues in the output.

  • 'omitnan'- 忽视values in the input. The product of elements containingvalues is the product of all non-元素。如果所有元素是, 然后cumprod返回1。

Output Arguments

全部收缩

累积产品array, returned as a vector, matrix, or multidimensional array of the same size as the input array一个

班级b与班级相同一个除非一个逻辑, 在这种情况下bdouble

更多关于

全部收缩

第一个nonsingleton维度

第一个非语言尺寸是数组的第一个维度,其大小不等于1

For example:

  • 如果X是一个1 x-n行矢量,那么第二维是第一个nonsingleton尺寸X

  • 如果X是一个1 x-0-b的空数组,那么第二维是第一个nonsingleton维X

  • 如果X1-by-1-by-3数组,那么third dimension is the first nonsingleton dimension ofX

Tips

  • MATLAB中的许多累积功能®万博1manbetx支持'撤销'option. This option allows quick directional calculations without needing a flip or reflection of the input array.

Extended Capabilities

版本历史记录

在R2006a之前引入

也可以看看

|||||