基本的Matlab for循环

时间:2019-04-23 04:53:22

标签: matlab

class _MapActivityState extends State<MapActivity> {
  GoogleMapController _controller;
  static LatLng _center = LatLng(0.0, 0.0);
  Position currentLocation;
  Set<Marker> _markers = {};

  void _onMapCreated(GoogleMapController controller) {
    setState(() {
      _controller = controller;
    });
  }

  @override
  void initState() {
    super.initState();
    setState(() {
      getUserLocation();
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomPadding: false,
      appBar: AppBar(
        title: Text("Home"),
      ),
      body: Stack(
        children: <Widget>[
          GoogleMap(
            onMapCreated: _onMapCreated,
            initialCameraPosition: CameraPosition(target: _center, zoom: 15),
            markers: _markers,
          ),
        ],
      ),
    );
  }
 getUserLocation() async {
    currentLocation = await locateUser();
    setState(() {
      for (int i = 0; i < myresponse.data.length; i++) {
        _markers.add(Marker(
            markerId: MarkerId(myresponse[i].userId),
            position: LatLng(double.parse(myresponse[i].latitude),
                double.parse(myresponse[i].longitude)),
            icon: myresponse[i].capacity.contains("7.2")
                ? BitmapDescriptor.fromAsset(
                    'assets/charger_location.png',
                  )
                : BitmapDescriptor.fromAsset(
                    'assets/marker_green.png',
                  ),
            infoWindow: InfoWindow(
                title: myresponse[i].stationName,
                snippet: myresponse[i].contactPerson,
                onTap: () => _onTap(myresponse[i]))));
      }
    });
 }
}

我将不胜感激! for循环条件以及第三行以及它们如何协同工作,我还不太了解

1 个答案:

答案 0 :(得分:3)

那么,人行道就来了。

A = 2;

A是一个长度为1的数组,其中2是唯一元素。

for x = 0:2:4

请查看for帮助的Examples部分。您创建一个“迭代变量” x,它会迭代一个带有值[0, 2, 4]的数组。另请参见:操作员帮助的Examples部分。

A = [A, A*x];

将数组A与值A*x连接(将一个数组与一个标量相乘会得到一个长度相同的数组,其中每个元素都乘以给定的标量),然后重新将结果分配给A。另请参见Concatenating Matrices上的帮助。

  • 最初是A = [2]
  • 对于x = 0A = [[2], [2] * 0],即A = [2, 0]
  • 对于x = 2A = [[2, 0], [2, 0] * 2],即A = [2, 0, 4, 0]
  • 对于x = 4A = [[2, 0, 4, 0], [2, 0, 4, 0] * 4],即A = [2, 0, 4, 0, 8, 0, 16, 0]
end

for循环的结尾。

A

通过省略行尾的分号来隐式调用A函数,以输出display的内容,有关解释,请参见here