我希望在MATLAB中创建一个简单的圆形图,其中模型显示沿着圆圈移动的点,其中半径和角速度由用户定义。
RADIANS / SEC中的角速度
我在MATLAB编码方面相对较新,所以任何帮助都非常有用!
我试过这段代码:
r=1;
t = 0:.01:2*pi;
x = r*cos(t);
y = r*sin(t);
comet(x,y);
但是当我改变0.01值时,点不会移动得更快,它只会跳过更多的曲线,我也不确定增量是否以弧度为单位。
感谢您的时间
答案 0 :(得分:1)
已修改版本:请参阅以前版本的修改历史记录。
Radius = 10;
AngularVelocity = 5; % in deg / s
AngleStep = 0.1
Angles = AngleStep : AngleStep : 2*pi;
CircleX = [Radius]; % empty array
CircleY = [0]; % empty array
%Initial zero-angle plot whose data we'll keep updating in the for loop:
a = plot([CircleX,CircleX], [CircleY,CircleY], 'r:');
hold on;
b = plot(CircleX, CircleY, 'o', 'markeredgecolor', 'k', 'markerfacecolor','g');
axis([-Radius, +Radius, -Radius, +Radius]); % make sure the axis is fixed
axis equal; % make x and y pixels of equal size so it "looks" a circle!
hold off;
for t = Angles
CircleX(end+1) = Radius * cos (t); % append point at end of CircleX array
CircleY(end+1) = Radius * sin (t); % append point at end of Circley array
set(a,'xdata',CircleX,'ydata',CircleY); % update plot 'a' data
set(b,'xdata', CircleX(end), 'ydata', CircleY(end)); % update plot 'b' data
drawnow; % ensure intermediate frames are shown!
pause(AngleStep/AngularVelocity) % pause the right amount of time!
end
与以前的版本相比,此编辑进行了两项更改:
axes
个对象(即容纳绘图的容器)