当前位置:   article > 正文

Matlab实现读取CSV文件字符串数据_matlab怎么读csv中的字符串

matlab怎么读csv中的字符串

读取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          白
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/782920
推荐阅读
相关标签
  

闽ICP备14008679号