33 lines
920 B
Mathematica
33 lines
920 B
Mathematica
|
function data = get_imudata(filepath, dataStructArray)
|
|||
|
% 打开文件以供读取
|
|||
|
fileID = fopen(filepath, 'r');
|
|||
|
|
|||
|
if fileID == -1
|
|||
|
error('无法打开文件:%s', filepath);
|
|||
|
end
|
|||
|
|
|||
|
% 逐行读取文件内容
|
|||
|
tline = fgetl(fileID);
|
|||
|
while ischar(tline)
|
|||
|
% 使用正则表达式来匹配行中的数值部分
|
|||
|
tokens = regexp(tline, '-?\d+\.\d+', 'match');
|
|||
|
|
|||
|
% 将字符串数组转换为数值数组
|
|||
|
values = str2double(tokens);
|
|||
|
|
|||
|
% 构建结构体
|
|||
|
if ~isempty(values)
|
|||
|
epoch = values(1); % 假设第一个数值是历元
|
|||
|
dataStructArray(end + 1).time = epoch;
|
|||
|
dataStructArray(end).values = values(2:end);
|
|||
|
end
|
|||
|
|
|||
|
tline = fgetl(fileID);
|
|||
|
end
|
|||
|
|
|||
|
% 关闭文件
|
|||
|
fclose(fileID);
|
|||
|
|
|||
|
% 返回填充好数据的结构体数组
|
|||
|
data = dataStructArray;
|
|||
|
end
|