0
我的問題是導入CSV文件內的數字與matlab變量具有相同的精度作爲原始數字。這是我的數據的例子(可以有與文件的頂部一個標題行的量X):用導入嚮導,並與下面的代碼Matlab導入CSV文件,標題和浮點精度數字
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
matlab中的雙精度足以滿足這個要求。你確定這不僅僅是一個顯示精度問題嗎? – slayton
另外,內置的'csvread'函數應該足夠了。 – Isaac
嗯,可以。我如何檢查這個?特別是對於時間變量,我需要高精度 – ajr