0

我的问题是将 CSV 文件中的数字导入到 matlab 变量中,其精度与原始数字相同。这是我的数据示例(可以有 X 行,文件顶部有一个标题):

g_B_esti_Velx, g_B_Velx, g_B_ACCx, g_B_esti_Vely, g_B_Vely, g_B_ACCy, g_B_esti_Velz, g_B_Velz, g_B_ACCz, ControlPitch, AnglePitch, ControlRoll, AngleRoll, Controlyaw, AngleYaw, Controlthrust, g_throttle, msgbatteryVoltage, msgcurrent, msgcapacity_mAh, time, index, tracking, detected
-0.266192,-1.072520,0.788713,0.163473,0.623330,-0.333946,0.000000,-0.773519,0.451613,7,-0.050615,0,-0.017453,0,-0.331613,128,472,142,97,2227,1340731788.614960,179,1,1
-0.270800,-0.486626,0.876130,0.125808,0.329368,-1.245129,0.000000,-0.459128,0.193548,40,-0.033161,-35,-0.017453,0,0.558505,128,472,142,99,2227,1340731788.715275,180,1,1

我已经使用导入向导和以下代码成功导入了数据。但问题是数字导入只有双精度,这是不够的。

fid = fopen('mk-2012-6-26-19-29.csv');
mydata = textscan(fid,'%s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s','Delimiter',',','CollectOutput',1);
fclose(fid);
mydata = [cellfun(@str2double,[mydata{1:end}])]';
whos mydata

和 matlab 导入向导结果:

newData1 = importdata('mk-2012-6-26-19-29.csv');
for i = 1:size(newData1.colheaders, 2)  % variable count
    assignin('base', genvarname(newData1.colheaders{i}), newData1.data(:,i)); %limit range on first parameter with :
end

我正在使用 Matlab R2011a

4

1 回答 1

1

问题似乎只出在我的 Matlab 显示精度上

以下命令允许我检查:

>> format long
>> time_mk(1,1)

ans =

     1.340731788614960e+09

结果与我的问题的第一行时间变量匹配。

于 2012-11-28T16:56:37.193 回答