필터 지우기
필터 지우기

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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by