我有一個正方形,它根據列向量 x(在底部)沿 x 軸來回移動。我想為正方形沿 x 軸來回滑動的運動設定影片。我嘗試在 for 回圈中使用 patch、hold on、hold off 和 Get Frame 函式,但這不起作用。相反,結果是正方形被弄臟了,因為舊正方形沒有從圖中洗掉。這是代碼:
clf
s = .1;
figure(1);
axis equal;
axis([-1 1 -1 1]);
for i = 1:length(x)
hold on
X = [x(i,1) - .5*s;
x(i,1) .5*s;
x(i,1) .5*s;
x(i,1) - .5*s;];
Y = [-.5*s;
-.5*s;
.5*s;
.5*s];
patch(X,Y,'k');
hold off;
h = gca;
F(i) = getframe;
end
movie(F);
這是列向量 x:
0.250000000000000 0.230782159143542 0.176280043536689 0.0953146856798128 0.000650212865865713 -0.0932030485077490 -0.172186726125664 -0.224543041359108 -0.242303458811820 -0.222203182817347 -0.166192085851484 -0.0817507793230268 0.0186298767049816 0.118170991653033 0.198905540101543 0.246001260876051 0.250959024174034 0.213107724416597 0.138822733533125 0.0407394702062158 -0.0642948796656877 -0.158085053404849 -0.224759025665608 -0.253100286376047 -0.238297378581389 -0.182618266275528 -0.0958896904713370 0.00602839522197084 0.104668511135333 0.183752954307020 0.231574999618735 0.242127812051811 0.214632538642815 0.153856203337548 0.0689710768423088 - 0.110309039989803090703033333328,0.24.>>]但0.1888836333266085980888,0.288,0.288,0.240.28038,0.288,0.0.280,0.288,0.218.0.28,0.0.28038,0.1288.>>]但0.1888836332888,0.246038,0.188,0.068,0.11,5633303088,0.11,598,0.120.18.08,0.128.>>191877626928792 0.234364270672030 0.240941167981351 0.209893379667572 0.145130717726666 0.0553977698549078 -0.0457864898288502 -0.141584098341353 -0.214945647396668 -0.252189311075765 -0.246607701950267 -0.199000344173733 -0.117539948553725 -0.0163532898953576 0.0870695406469115 0.175127325624604 0.233430214463870 0.252410945754133 0.228805022755430 0.165868916165404 0.0741157391779560 -0.0299825244149044 -0.127575941311610 -0.201938733706939 -0.241944848784945 -0.242264519853537 -0.203786790215477 -0.132560148710489 -0.0395394071796979 0.0608871776036858 0.152636629298216 0.220295640189107 0.252442054488179 0.243446202365058 0.195322881013323 0.116647868987791 0.0209866982124944 -0.0762128632358914 -0.160101037237629 -0.218549398091714 -0.243311095720934 -0.230961374436814 -0.183209095455776 -0.106644747551930 -0.0123109118042467 0。0857290198345198 0.171900620989060 0.231541484378119 0.254192056475618 0.235371165049059 0.178352335891224 0.0928137722294060 -0.00672172862573606 -0.104037530998919 -0.183858736347838
uj5u.com熱心網友回復:
我剛剛結束了補丁功能,因為它似乎不適用于 hold on hold off 命令。我使用繪圖功能來繪制四條線,如下所示。
clc
clf
s = .25;
min = -2;
max = 2;
for i = 1:length(x)
X = [x(i,1)-.5*s, x(i,1) .5*s];
Y = [-.5*s, -.5*s];
plot(X,Y,'b');
axis equal
axis([min max min max]);
hold on;
X = [x(i,1) .5*s, x(i,1) .5*s];
Y = [-.5*s, .5*s];
plot(X,Y,'b');
axis equal
axis([min max min max]);
hold on;
X = [x(i,1) .5*s, x(i,1)-.5*s];
Y = [.5*s, .5*s];
plot(X,Y,'b');
axis equal;
axis([min max min max]);
hold on;
X = [x(i,1)-.5*s, x(i,1)-.5*s];
Y = [.5*s, -.5*s];
plot(X,Y,'b');
axis equal;
axis([min max min max]);
hold off
F(i) = getframe;
end
movie(F)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/412035.html
標籤:
上一篇:Thomas演算法中的初始系數
