フィルターのクリア

how can i save the full timestamp ID number?

2 ビュー (過去 30 日間)
Adam
Adam 2012 年 1 月 25 日
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 件のコメント
Dr. Seis
Dr. Seis 2012 年 1 月 25 日
Can you post the code you use to save the data to the text file?
Adam
Adam 2012 年 1 月 25 日
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);

サインインしてコメントする。

採用された回答

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 1 月 25 日
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 件のコメント
Adam
Adam 2012 年 1 月 25 日
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() ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by