Main Content

for

用来重复指定次数的 for 循环

语法

for index = values
   statements
end

说明

示例

for index = values, statements, end 在循环中将一组语句执行指定的次数。

如果 colon, : 运算使用 fi 对象作为索引,则 fi 对象必须为整数。

有关详细信息,请参考 MATLAB® for 参考页。

示例

全部折叠

使用 fi 对象作为 for 循环的索引。

a = fi(1,0,8,0);
b = fi(2,0,8,0);
c = fi(10,0,8,0);

for x = a:b:c
 x
end
x = 
     1

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     3

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     5

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     7

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0
x = 
     9

          DataTypeMode: Fixed-point: binary point scaling
            Signedness: Unsigned
            WordLength: 8
        FractionLength: 0

扩展功能

C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。

版本历史记录

在 R2014b 中推出