Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-14, 20:13   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 在MATLAB中创建沿图形移动的点

我正在寻找在MATLAB中创建一个简单的log(x)图,其中模型显示点随时间沿曲线移动的情况。

总体目标是使这些图中的两个相互并排,并对它们应用一种算法。我真的不确定从哪里开始。

我在MATLAB编码方面相对较新,因此任何帮助都将非常有用!

谢谢卢克



回答:

这是@Jacob解决方案的一个变体。无需在每个帧( clf )上重新绘制所有内容,我们只需更新该点的位置即可:

%# control animation speed DELAY = 0.01; numPoints = 600; %# create data x = linspace(0,10,numPoints); y = log(x); %# plot graph figure('DoubleBuffer','on') %# no flickering plot(x,y, 'LineWidth',2), grid on xlabel('x'), ylabel('y'), title('y = log(x)') %# create moving point + coords text hLine = line('XData',x(1), 'YData',y(1), 'Color','r', ... 'Marker','o', 'MarkerSize',6, 'LineWidth',2); hTxt = text(x(1), y(1), sprintf('(%.3f,%.3f)',x(1),y(1)), ... 'Color',[0.2 0.2 0.2], 'FontSize',8, ... 'HorizontalAlignment','left', 'VerticalAlignment','top'); %# infinite loop i = 1; %# index while true %# update point & text set(hLine, 'XData',x(i), 'YData',y(i)) set(hTxt, 'Position',[x(i) y(i)], ... 'String',sprintf('(%.3f,%.3f)',[x(i) y(i)])) drawnow %# force refresh %#pause(DELAY) %# slow down animation i = rem(i+1,numPoints)+1; %# circular increment if ~ishandle(hLine), break; end %# in case you close the figure end



更多&回答...
poster 当前离线   回复时引用此帖
回复

主题工具
显示模式

发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 05:15


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.