赞
踩
读取USB传输过来的数据文件,并进行格式转换和绘图显示
clear ; close all; fid = fopen('E:\usb\ppx-6-queue-2.csv'); %打开并获取csv文件 [A,COUNT]=fscanf(fid,'%s',inf); %由于csv文件中为字符串数字,所以需要进行格式转换 A=strrep(A,'""','","'); A=regexp(A, ',','split'); A=strrep(A,'"',' '); A=strtrim(A); A=hex2dec(A); %将HEX码转为10进制码 [rows,columns] = size(A); %将A矩阵转换为16 * columns/16大小的矩阵。 mat_A = reshape(A,16,columns/16)'; %由于从FIFO中取数据和存数据之间存在固有的顺序错误,所以需要对数据进行顺序调整 mat_A(:,[3 1]) = mat_A(:,[1 3]); mat_A(:,[4 2]) = mat_A(:,[2 4]); mat_A(:,[7 5]) = mat_A(:,[5 7]); mat_A(:,[8 6]) = mat_A(:,[6 8]); mat_A(:,[11 9]) = mat_A(:,[9 11]); mat_A(:,[12 10]) = mat_A(:,[10 12]); mat_A(:,[15 13]) = mat_A(:,[13 15]); mat_A(:,[16 14]) = mat_A(:,[14 16]); A_change = reshape(mat_A',rows,1); %将波形数据分别显示在不同的窗口中 % plot(A_change(1:1000)) % figure % plot(A(1:1000)) %将波形数据显示在同一个窗口内 plot(A_change(1:1000),'r') hold on plot(A(1:1000)) %挑选数据集中的某几行进行观测 % z = 1; % for i = 1:1:rows/16 % if(rem(i,1025) == 0) % for j = 1:1:16 % hold(z,j) = mat_A(i,j); % end % z = z + 1; % end % end %plot中绘图的标记色 % 标记符 颜色 % r 红 % g 绿 % b 蓝 % c 蓝绿 % m 紫红 % y 黄 % k 黑 % w 白
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。