max
fi
对象数组中的最大元素
说明
示例
向量中的最大元素
创建一个定点向量,并返回向量的最大值。
A = fi([1,5,4,9,2],1,16); M = max(A)
M = 9 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11
每个矩阵行的最大元素
创建一个定点矩阵。
A = fi(magic(4),1,16)
A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10
通过沿第二个维度查找最大值来查找每一行的最大元素。
M = max(A,[],2)
M = 16 11 12 15 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10
输出向量 M 是一个列向量,包含了每一行的最大元素。
每个矩阵列的最大元素
创建一个定点矩阵。
A = fi(magic(4),1,16)
A = 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15 1 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10
查找每一列的最大元素。
M = max(A)
M = 16 14 15 13 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10
输出 M
是一个行向量,包含了 A
中每一列的最大元素。
查找每个最大元素的索引。
[M,I] = max(A)
M = 16 14 15 13 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 10
I = 1×4
1 4 4 1
向量 I
包含 M
中最小元素的索引。
两个数组中的最大元素
创建两个相同大小的定点数组。
A = fi([2.3,4.7,6;0,7,9.23],1,16); B = fi([9.8,3.21,1.6;pi,2.3,1],1,16);
从 A
或 B
中查找最大元素。
C = max(A,B)
C = 9.7998 4.7002 6.0000 3.1416 7.0000 9.2300 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 11
C
包含 A
和 B
中每对对应元素中的最大元素。
复数向量的最大元素
创建一个复数定点向量 a
。
a = fi([1+2i,3+6i,6+3i,2-4i],1,16)
a = 1.0000 + 2.0000i 3.0000 + 6.0000i 6.0000 + 3.0000i 2.0000 - 4.0000i DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 12
该函数通过提取具有最大幅值的元素查找复数向量的最大元素。
abs(a)
ans = 2.2361 6.7083 6.7083 4.4722 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 12
在向量 a
中,位置 2
和 3
处的最大元素的幅值为 6.7083
。max
函数返回输出 x
中的最大元素以及该元素在输出 y
中的索引。
[x,y] = max(a)
x = 3.0000 + 6.0000i DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 16 FractionLength: 12
y = 2
尽管索引 2 和 3 处的元素具有相同的幅值,但始终返回该值第一次出现位置的索引。
输入参数
A
— 输入 fi
数组
标量 | 向量 | 矩阵 | 多维数组
B
— 其他输入数组
标量 | 向量 | 矩阵 | 多维数组
其他输入 fi
或数值数组,指定为标量、向量、矩阵或多维数组。A
和 B
的维度必须匹配,除非其中一个是标量。
max
函数忽略 NaNs
。
数据类型:fi
|single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
复数支持:是
dim
— 运算维度
正整数标量
运算维度,指定为正整数标量。dim
也可以是 fi
对象。如果不指定值,则默认值是大小不等于 1 的第一个数组维度。
数据类型:fi
|single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
输出参数
扩展功能
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
HDL 代码生成
使用 HDL Coder™ 为 FPGA 和 ASIC 设计生成 VHDL、Verilog 和 SystemVerilog 代码。
版本历史记录
在 R2006a 之前推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)