for sits = 1:stepsize segmentLength = 0.1; if run_RRTconnect == 1 time = 0; avg_its = 0; avg_path = 0; for i = 1:num_of_runs [n_its,path_n,run_time] = RRTconnect_3D(dim,segmentLength,random_world,show_output); time = time + run_time; avg_its = avg_its + n_its; avg_path = avg_path + path_n; end str1 = ['The time taken by RRT-Connect for ', num2str(num_of_runs), ' runs is ', num2str(time)]; str2 = ['The averagae time taken by RRT-Connect for each run is ', num2str(time/num_of_runs)]; str3 = ['The averagae number of states explored by RRT-Connect for each run is ', num2str(avg_its/num_of_runs)]; str4 = ['The averagae number of state in Path by RRT-Connect for each run is ', num2str(avg_path/num_of_runs)]; disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); disp(str1); disp(str2); disp(str3); disp(str4); disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); plot3(0.15,0,0.36,'.k','Markersize',30); plot3([0.15 0.15],[0 0],[0.27 0.45],'r','LineWidth',5); end end
时间: 2024-04-01 18:35:48 浏览: 44
这段代码是在上面的for循环体内部继续执行的。在判断run_RRTconnect是否等于1之后,又定义了四个字符串变量str1、str2、str3、str4,分别存储了不同的输出信息。然后使用disp函数输出了这四个字符串变量的值,并在每个字符串变量的前后加入了一些分隔线。最后还调用了plot3函数,画出了一个点和一条线。整个for循环体的结构是这样的:当run_RRTconnect等于1时,循环执行num_of_runs次RRTconnect_3D函数,并累加运行时间、探索的状态数和路径上的状态数;当循环结束后,输出统计信息和绘制图形。
相关问题
for sits = 1:stepsize segmentLength = 0.1; if run_RRTconnect == 1 time = 0; avg_its = 0; avg_path = 0; for i = 1:num_of_runs [n_its,path_n,run_time] = RRTconnect_3D(dim,segmentLength,random_world,show_output); time = time + run_time; avg_its = avg_its + n_its; avg_path = avg_path + path_n; end
这段代码中使用了for循环,循环变量为sits,循环次数为stepsize。在循环体内部定义了变量segmentLength的值为0.1,然后判断run_RRTconnect是否等于1,如果是,则定义变量time、avg_its和avg_path的值都为0,接着再使用for循环,循环变量为i,循环次数为num_of_runs。在循环体内部调用了函数RRTconnect_3D,并将返回值分别赋值给变量n_its、path_n和run_time。然后累加变量time、avg_its和avg_path的值。最后,在循环体外部结束了for循环sits,并且此时变量time、avg_its和avg_path的值都是所有循环的累加值。
class MyCar: steer_shape='rectangle' __weight=3000 def init(self,n_wheel,n_sits): self.n_wheel=n_wheel self.n_sits=n_sits def run(self): print("The car has already started") print(MyCar.dict) print(MyCar._MyCar__weight) mycar=MyCar(4,5) mycar.run() 在上例基础上,通过mycar采用两种不同方法访问属性 n_wheel
可以通过以下两种方法访问属性 n_wheel:
1. 直接使用实例对象 mycar.n_wheel,如下所示:
```python
print(mycar.n_wheel)
```
2. 使用类对象 MyCar 和属性名 n_wheel,通过类访问实例属性,如下所示:
```python
print(MyCar.n_wheel.__get__(mycar))
```
这两种方法都可以访问到实例属性 n_wheel 的值。
阅读全文