作业帮 > 综合 > 作业

如何使用循环语句缩短程序

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/21 18:50:09
如何使用循环语句缩短程序
subplot(521);
plot(index,a1);
subplot(522);
plot(index,a2);
subplot(523);
plot(index,a3);
subplot(524);
plot(index,a4);
subplot(525);
plot(index,a5);
subplot(526);
plot(index,d1);
subplot(527);
plot(index,d2);
subplot(528);
plot(index,d3);
subplot(529);
plot(index,d4);
subplot(5,2,10);
plot(index,d5); 以上是程序的一部分,我想问下可不可以把这段程序用循环语句简练的表达出来,这样实在是太麻烦了,麻烦大神老师们给看看,跪谢!
也许可以这样:
1、subplot语句因为其参数是有规律地递增,所以是完全可以用循环表达的.
2、plot语句,其中的index和第二个参数是常量还是变量?如果index是变量,则可以在每次循环中进行更新.第二个参数,完全可以把a1, a2, a3, a4,a5, d1,等等,这样的参数事先组成一个数组,然后每次循环读取对应的值,然后数组的索引递增,这样就能把两个语句都放到循环中了.