0
votes

My problem is to import numbers inside CSV file to matlab variable with the same precision as original number. Here's an example of my data (there can be X amount of rows with one header on top of file):

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

I have successfully imported data with import wizard and with following code. But the problem is that number import is only with double precision, which is not sufficient.

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

and matlab import wizard result:

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

I'm using Matlab R2011a

1
Double precision in matlab is more than sufficient for this. Are you sure this isn't simply a display precision problem? - slayton
Also, the built-in csvread function should be sufficient. - Isaac
hmm, could be. How to i check this? Specially for time variable i require high precision - ajr
format longsolves the display precision issues. - ajr

1 Answers

1
votes

Problem seemed to only be with my Matlab display precision

Following command allowed me to check this:

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

ans =

     1.340731788614960e+09

Result matches the first row time variable on my question.