开发者

matlab exporting data

I have a daq card from which data is continuosly acquired every 100 ms. Now I want to create a txt file which contains all the data. This txt file should also have a time stamp and should have 5 column headers - zeit , channel1, channel2.... channel4.

This is the code I could write but I am confused how to print the data after the headers. Also after every 100 ms secs new data comes in and this has to be appended to the end of the file .The time stamp is in a specific format because later I need to search for a number.

% Time stamp 
A = datestr(now, 'mmmm dd, yyyy HH:MM:SS.FFF ')
format short g
datevec(A)

fid = fopen('开发者_如何学编程acq.txt','w');
fprintf(fid,'%s\t',A)

A = 'Zeit';
dataName = 'channel';

fid = fopen('acq.txt','w');

fprintf(fid,'%s\t',A)  
%# loop to write the rest of the header 

x=5
for iModel = 1:x
fprintf(fid,'%s_%i\t',dataName,iModel); 
end 


data =  rand( 10,10);


fprintf( 'acq.txt' , '%i' ,data); 


If you dont close the file, there is no reason to open it twice. Two consecutive fprintfs would get you started after the first fopen:

fprintf(fid,'%s\t',datestr(now, 'mmmm dd, yyyy HH:MM:SS.FFF '))
fprintf(fid,'%s\t%s1\t%s2\t%s3\t%s4\t','Zeit',dataName,dataName,dataName,dataName)

to set up the headers. At this point remember to use fclose(fid). You can now loop through each time your data is read, and open the file for append fida = fopen('acq.txt','a'); followed by formatted data output:

fprintf(fida,'%f %f %f %f %f %f %f %f %f %f\n',data')

For some reason matlab displays the data in the first row first, so transposing it puts it in the same shape as the data as represented in matlab. Remember to close these files or you might run into errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜