Matlab 实现读取txt数据进行绘图

 

function distanceFun() 
close all; clear all; clc;
filenameqx = 'E:\QTCode\build-SHNADataAnalysis-Desktop_Qt_5_14_0_MSVC2017_64bit-Debug\QX\QX.txt';
fid = fopen(filenameqx);
QX = textscan(fid,'%s');
fclose(fid);
strHoritionalQX=QX{1};
strHoritionalQX=str2double(strHoritionalQX(4:length(strHoritionalQX)));
filenamelf = 'E:\QTCode\build-SHNADataAnalysis-Desktop_Qt_5_14_0_MSVC2017_64bit-Debug\LF\LF.txt';
fidlf = fopen(filenamelf);
LF = textscan(fidlf,'%s');
fclose(fidlf);
strHoritionalLF=LF{1};
strHoritionalLF=str2double(strHoritionalLF(4:length(strHoritionalLF)));
m=length(strHoritionalQX);
mLF=length(strHoritionalLF);
horizontalQX = [];
indexQX =[];
horizontalLF = [];
indexLF =[];
standartHorizontal =[];
standartIndex = [];
 for i=1:m
           horizontalQX(i)=strHoritionalQX(i); 
           indexQX(i)=i;
           standartHorizontal(i)=0;
           standartIndex(i)=i;
 end
  for i=1:mLF
           horizontalLF(i)=strHoritionalLF(i); 
           indexLF(i)=i;
  end
 %获取最大值和最小值
 [QXMax,QXindex] = max(horizontalQX);
 [LFMax,LFindex] = max(horizontalLF);
 [QXmin,QXindexmin] = min(horizontalQX);
 [LFmin,LFindexmin] = min(horizontalLF);
figure(3);
F1=plot(indexQX,horizontalQX,'g.-');
hold on 
F2=plot(indexLF,horizontalLF,'b.-');
F3=plot(standartIndex,standartHorizontal,'r.-');
xlabel('time(s)');
ylabel('水平误差(m)');
if m>=mLF&&QXMax>=LFMax
    axis([0,m,0,QXMax]);
elseif m>=mLF&&QXMax<=LFMax
    axis([0, m ,0, LFMax]);
elseif m<=mLF&&QXMax>=LFMax
    axis([0, mLF, 0, QXMax]);
elseif m<=mLF&&QXMax<=LFMax
    axis([0 ,mLF, 0, LFMax]);
end
grid on;   %应用分格线(网格)
h = legend([F2,F1,F3],'六分科技','千寻位置','标定数据');      %加一个图例,句柄h。
set(h,'fontsize',16,'edgecolor','w','textcolor','k') ;  %对图例h进行精细设置
%text(indexQX(QXindex),horizontalQX(QXindex),'o','color','r');
%标记最大值
text(indexQX(QXindex),horizontalQX(QXindex),['(',num2str(indexQX(QXindex)),',',num2str(horizontalQX(QXindex)),')'],'color','b');
text(indexLF(LFindex),horizontalLF(LFindex),['(',num2str(indexLF(LFindex)),',',num2str(horizontalLF(LFindex)),')'],'color','k');
text(indexQX(QXindexmin),horizontalQX(QXindexmin),['(',num2str(indexQX(QXindexmin)),',',num2str(horizontalQX(QXindexmin)),')'],'color','b');
text(indexLF(LFindexmin),horizontalLF(LFindexmin),['(',num2str(indexLF(LFindexmin)),',',num2str(horizontalLF(LFindexmin)),')'],'color','k');
h1=title("闵行高架下(全遮挡)—水平误差");
set(h1,'fontsize',16);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值