• matlab绘制动图


    %% 本程序用作绘制matlab动图 dot 20220728

    % Poten
    data1 = importdata(‘poten_dot2.txt’);
    inition_30 = min(find(data1.data(:,1)>=30));
    Poten_dot = data1.data(inition_30:end,:);

    EEF_Error_X = (Poten_dot(:,34) - Poten_dot(1,34))*100;
    EEF_Error_Y = (Poten_dot(:,35) - Poten_dot(1,35))*100;
    EEF_Error_Z = (Poten_dot(:,36) - Poten_dot(1,36))*100;

    Poten_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2 );

    % MPC
    data1 = importdata(‘MPC_dot.txt’);
    inition_30 = min(find(data1.data(:,1)>=30));
    inition_80 = min(find(data1.data(:,1)>=90));
    MPC_dot = data1.data(inition_30:inition_80,:);

    EEF_Error_X = (MPC_dot(:,34) - MPC_dot(1,34))*100; ;
    EEF_Error_Y = (MPC_dot(:,35) - MPC_dot(1,35))*100; ;
    EEF_Error_Z = (MPC_dot(:,36) - MPC_dot(1,36) )*100;;

    MPC_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2);

    % Feedback
    data1 = importdata(‘Feedback_dot2.txt’);
    inition_30 = min(find(data1.data(:,1)>=30));
    Feedback_dot = data1.data(inition_30:end,:);

    EEF_Error_X = (Feedback_dot(:,34) - Feedback_dot(1,34))*100;
    EEF_Error_Y = (Feedback_dot(:,35) - Feedback_dot(1,35))*100;
    EEF_Error_Z = (Feedback_dot(:,36) - Feedback_dot(1,36))*100;

    Feedback_EEF_Norm = sqrt(EEF_Error_X.^2 + EEF_Error_Y.^2 + EEF_Error_Z.^2);

    data_x = Poten_dot(:,1)-30;
    data_y = Poten_EEF_Norm;

    writerObj=VideoWriter(‘ALL.mp4’,‘MPEG-4’); %// 定义一个视频文件用来存动画 mp4

    open(writerObj); %// 打开该视频文件

    figure
    for i=2:66:length(data_x)

    scatter(MPC_dot(i)-30,MPC_EEF_Norm(i),60,[1 0 0])
    hold on
    plot(MPC_dot(1:i)-30,MPC_EEF_Norm(1:i),'LineWidth',1.5,'Color',[1 0 0])
    
    scatter(Poten_dot(i)-30,Poten_EEF_Norm(i),60,[0 1 0])
    hold on
    plot(Poten_dot(1:i)-30,Poten_EEF_Norm(1:i),'LineWidth',1.5,'Color',[0 1 0])
    
    scatter(Feedback_dot(i)-30,Feedback_EEF_Norm(i),60,[0 0 1])
    hold on
    plot(Feedback_dot(1:i)-30,Feedback_EEF_Norm(1:i),'LineWidth',1.5,'Color',[0 0 1])
    
    
    
    hold off
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    %
    % scatter(data_x(i),data_y(i),60,[0 0 1])
    % hold on
    % plot(data_x(1:i),data_y(1:i),‘LineWidth’,1.5,‘Color’,[0 0 1])
    % hold off
    %
    axis([0 60 0 6])
    grid on

    xlabel('Time(s)','FontSize',25)
    ylabel('Error(cm)','FontSize',25)
    F=getframe(gcf);
    frame = F; %// 把图像存入视频文件中
    writeVideo(writerObj,frame)
    
    • 1
    • 2
    • 3
    • 4
    • 5

    end
    close(writerObj); %// 关闭视频文件句柄

  • 相关阅读:
    数据结构题目收录(七)
    基于Eigen求解线性方程组Ax=b的性能分析
    MySQL锁机制详解
    如何理解某一个开发框架的意图,从而去写和落代码文件位置不会出错
    static静态成员变量使用@Value注入方式
    ROS2自学笔记:launch文件完整编写流程
    K8S ingressv1.1.3 部署
    移动WEB开发之rem布局--less基础
    CMake Tutorial 巡礼(8)_为测试白板添加支持
    AOSP ~ GDB 远程调试
  • 原文地址:https://blog.csdn.net/weixin_42493873/article/details/126149950