Matlab与C实时联合仿真二

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Blues_lizhen/article/details/78123947

方式
C数据实时写入文本c.txt
Matlab实时读取c.txt数据

matlab程序部分

clc
clear all
close all


figure(1)
%坐标轴范围
axis([-10 10 -10 10]);
plot([0 10],[0,10],'b-');
xlabel('x');
ylabel('y');
grid on
hold on 
label=0;
stop=0;
%实现数据在画图中实时显示,动态更新
while ~stop
    data=textread('E:\work\workspace\c.txt');
    shape=size(data);
    len=shape(1);
    %检测是否有新数据
    if len>label
        axis([-10 10 -10 10]);
        %将更新的数据动态显示
        plot(data(1:len,1),data(1:len,1),'r-');
        grid on
        hold on 
        drawnow;
        %记录数据长度
        label=len;
        %终止条件
        if data(len,1)>10
            stop=1;
        end

    end



end

结果如下:数据来自于C程序,MATLAB做实时动态显示

图1

图2

猜你喜欢

转载自blog.csdn.net/Blues_lizhen/article/details/78123947