Filter löschen
Filter löschen

how can i save the full timestamp ID number?

2 Ansichten (letzte 30 Tage)
Adam
Adam am 25 Jan. 2012
hi guys
i have some data which i fetch from device that samples freq, volt and power. each time i recieve a sample, ill give it a datenum ID using the matlab function "now". Then ill save the data into a .txt file. The problem is, that when i save the data, the datenum ID numbers are cuttoff, making all of them the same number. That means that when i load the data again, all of the samples has the same datenum ID number, which makes it impossible to plot the data?
here is an example of what my .txt file might look like. the 4. collumn contains the timestamp ID numbers.
49886 2.361440e+004 1.339829e+003 7.348937e+005
49886 2.361004e+004 1.339829e+003 7.348937e+005
49897 2.358127e+004 1.337393e+003 7.348937e+005
49921 2.360107e+004 1.337393e+003 7.348937e+005
49928 2.359396e+004 1.337393e+003 7.348937e+005
49931 2.357588e+004 1.337393e+003 7.348937e+005
49938 2.356435e+004 1.334957e+003 7.348937e+005
Does anybody know how i can save the full timestamp ID number?
  2 Kommentare
Dr. Seis
Dr. Seis am 25 Jan. 2012
Can you post the code you use to save the data to the text file?
Adam
Adam am 25 Jan. 2012
Yes, here it is:
function SaveData(data)
%first collumn of 'data' is freq
%second collumn of 'data' is voltage
%third collumn of 'data' is power
%fourth collumn of 'data' is datenum ID
[filename, filepath] = uiputfile()
fid = fopen(filename,'w');
fprintf(fid,'%6u %6u %6u 6u\n',data);
fclose(fid);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 25 Jan. 2012
If you use dlmwrite() then you can use the Precision argument to specify a format to write with, such as '%.16e'

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 25 Jan. 2012
You missed the '%' before the final 6u.
The %u format is for unsigned integers (in base 10.) When you use it to output a number which is not sufficiently close to an integer, then according to the fprintf() documentation,
If you specify a conversion that does not fit the data, such as a string conversion for a numeric value, MATLAB overrides the specified conversion, and uses %e.
It appears to me that a %.9f format would be consistent with the values for now() that are printed if you have
format long g
in effect. However, as best I calculate at the moment, millisecond resolution can be achieved with %.8f format.
  1 Kommentar
Adam
Adam am 25 Jan. 2012
okay thx. i will try this tomorrow.
I am using now() in another function called readData(), in which i am also saving the data and the numdate ID into the array with the name 'data'. Should i put the line "format long g", in readData() or in SaveData() ?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by