我在下面给出了csv.file部分
{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Microsoft Sans Serif;}}
\viewkind4\uc1\pard\lang1033\f0\fs17
$GPGGA, 142621.00, 4106.29338717, N, 02901.18386180, E, 5, 06, 7.2, 103.3\par
$SDDBT, 1.3, f, 0.3, M, 0.2, F*05\par
\par
$GPGGA, 142622.00, 4106.29339273, N, 02901.18387863, E, 5, 06, 7.2, 103.3\par
$SDDBT, 1.3, f, 0.3, M, 0.2, F*05\par
\par
$GPGGA, 142623.00, 4106.29339566, N, 02901.18386326, E, 5, 06, 7.2, 103.3\par
$SDDBT, 1.3, f, 0.3, M, 0.2, F*05\par
\par
.
.
.
由于我无法读取值103.3,因此我遇到了问题 并且我无法使程序读取2行2行(跳过" \ par"行)同时使用混合变量
这会得到/ par的rits但它没有格式化读数。我不确定使用" csvread或fscanf"
fid = fopen('filename','r+');
C = textscan(fid, '%s', 'Delimiter', '\n', 'CommentStyle', '\','headerlines',2);
C = C{:}; fclose(fid);
答案 0 :(得分:0)
我不确定文本扫描是否能够读取每一行,但我会使用fgets逐行读取您的文件:
% Initialize arrays
GPGGAArray = [];
SDDBTArray = [];
% open file
fid = fopen('filename','r+');
% Skip 2 header lines
currentLine = fgets(fid);
currentLine = fgets(fid);
while ischar(currentLine)
currentLine = fgets(fid);
if currentLine == -1
break;
end
% line with GPGGA
C1 = textscan(currentLine, '%s', 'Delimiter', ',');
currentLine = fgets(fid);
if currentLine == -1
break;
end
GPGGAArray = [GPGGAArray; [str2double(C1{1,1}{2}), str2double(C1{1,1}{3}), str2double(C1{1,1}{5}),...
str2double(C1{1,1}{7}), str2double(C1{1,1}{8}), str2double(C1{1,1}{9}), str2double(C1{1,1}{10}(1:end-4))]];
% line with SDDBT
C2 = textscan(currentLine, '%s', 'Delimiter', ',');
SDDBTArray = [SDDBTArray; [str2double(C2{1,1}{2}), str2double(C2{1,1}{4}), str2double(C2{1,1}{6}),...
str2double(C2{1,1}{7}(3:end-4))]];
% skip line with \par
currentLine = fgets(fid);
end
% Close file
fclose(fid);
请注意,C1和C2是带字符串的单元格数组。