如何在不使用for loop
的情况下一次绘制全部绘图?
下面的示例代码:
clear all,clf reset,tic,clc
plot_array_x1=[-0.1732050807568878 -0.6767949192431123 -1.366025403784439
0.1732050807568877 0.176794919243112 0.366025403784438
6.123233995736766e-17 0.5000000000000001 1];
plot_array_y1=[-0.09999999999999995 0.186602540378444 0.366025403784439
-0.1000000000000001 -0.6794228634059948 -1.366025403784439
0.2 0.4928203230275509 0.9999999999999998];
for ii=1:3
plot(plot_array_x1(ii,:),plot_array_y1(ii,:))
hold on
end
代码产生下面的图,但是它需要我使用for loop
才能避免使用for循环吗?
答案 0 :(得分:1)
您快到了。首先,转置数组,然后删除循环。
plot_array_x1=[-0.1732050807568878 -0.6767949192431123 -1.366025403784439;
0.1732050807568877 0.176794919243112 0.366025403784438;
6.123233995736766e-17 0.5000000000000001 1].';
plot_array_y1=[-0.09999999999999995 0.186602540378444 0.366025403784439;
-0.1000000000000001 -0.6794228634059948 -1.366025403784439;
0.2 0.4928203230275509 0.9999999999999998].';
figure(1)
plot(plot_array_x1,plot_array_y1)