以下是一个输出动图的程序:figure;frames_images = cell(1, (41-1)/5 + 1);for i=1:5:41 pcolor(xmesh/20,ymesh/20,vor_phase_ave(:,:,i)*20/42); shading interp; axis equal tight; axis([0 5 -3 3]); hold on; fill([0,0.5,0.5,0],[-3,-3,-0.5,-0.5],'w') fill([0,0.5,0.5,0],[-0.5,-0.5,0.5,0.5],'k');hold on; fill([0,0.5,0.5,0],[0.5,0.5,3,3],'w'); set(gca,'FontName','Times New Roman','FontSize',12); text(-1,0,'\ity/\itD ','FontSize', 14, 'FontName', 'times new roman'); text(2.5,-3.4,'\itx/\itD ','FontSize', 14, 'FontName', 'times new roman'); set(gca,'LineWidth',1.5); colormap jet; caxis([-10 10]); drawnow; frames_images{(i-1)/5 + 1} = frame2im(getframe(gcf)); waitforbuttonpress; endfilename = 'vordongtu2.gif';for idx = 1:length(frames_images) [A, map] = rgb2ind(frames_images{idx}, 256); if idx == 1 imwrite(A, map, filename, 'gif', 'LoopCount', Inf, 'DelayTime', 1); else imwrite(A, map, filename, 'gif', 'WriteMode', 'append', 'DelayTime', 1); end end
现在我想要每一个动图上都有一个标题,标题的程序为 text(2,3.5,'{\it\Phi} = (i-1)*0.05\pi ','FontSize', 14, 'FontName', 'times new roman'); end目的是为了标题也能随动图的变化而变化,应该如何在原程序中添加,麻烦直接在原程序中添加。
MATLAB动图问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
7条回答 默认 最新
关注 qq_47361278 晚上好🌙🌙🌙
本答案参考ChatGPT-3.5要在原程序中添加动态变化的标题,可以将
text
函数放在循环中,确保每一帧都会有一个对应的标题。以下是修改后的代码:figure; frames_images = cell(1, (41-1)/5 + 1); for i=1:5:41 pcolor(xmesh/20, ymesh/20, vor_phase_ave(:,:,i)*20/42); shading interp; axis equal tight; axis([0 5 -3 3]); hold on; fill([0,0.5,0.5,0],[-3,-3,-0.5,-0.5],'w') fill([0,0.5,0.5,0],[-0.5,-0.5,0.5,0.5],'k'); hold on; fill([0,0.5,0.5,0],[0.5,0.5,3,3],'w'); set(gca,'FontName','Times New Roman','FontSize',12); text(-1,0,'\ity/\itD ','FontSize', 14, 'FontName', 'times new roman'); text(2.5,-3.4,'\itx/\itD ','FontSize', 14, 'FontName', 'times new roman'); set(gca,'LineWidth',1.5); colormap jet; caxis([-10 10]); % 添加动态变化的标题 title_str = sprintf('{\\it\\Phi} = %.2f\\pi', (i-1)*0.05); text(2, 3.5, title_str, 'FontSize', 14, 'FontName', 'times new roman'); drawnow; frames_images{(i-1)/5 + 1} = frame2im(getframe(gcf)); waitforbuttonpress; end filename = 'vordongtu2.gif'; for idx = 1:length(frames_images) [A, map] = rgb2ind(frames_images{idx}, 256); if idx == 1 imwrite(A, map, filename, 'gif', 'LoopCount', Inf, 'DelayTime', 1); else imwrite(A, map, filename, 'gif', 'WriteMode', 'append', 'DelayTime', 1); end end
解决方案:
- 在循环中添加
title_str
变量,使用sprintf
函数根据当前帧的索引i
计算变化的标题。 - 在
text
函数中使用title_str
变量作为标题内容。 - 保持原有代码不变即可。
解决 无用评论 打赏 举报- 在循环中添加
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效