- see Running Script using Timer and note the comment by Alfonso Nieto-Castanon
- an alternative to cswrite is fopen( ..., 'a') together with fprintf. No need for a counter; it appends to the end of the file. Or maybe dlmwrite(filename, M, '-append')
Exporting value to .csv file with updated value from a timer
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a timer which updates a value in my script every minute
Period = 60; % Update period in seconds
tim = timer('Period', Period, 'ExecutionMode', 'fixedRate',...
'TimerFcn', 'MyScript');
start(tim)
stop(tim)
I want to store the updated value in the next row (same column) of a .csv file every time the timer resets
%Writes the current value to 60 mins.csv in row 1, column 1
csvwrite('60 mins.csv',MyValue,0,0);
My guess is that i need a counter to increase the row number with each updated value/timer iteration. I want to collect at least 1440 values (a full day).
Any thoughts?
Note: the timer IS supposed to leave the whole script on an infinite loop, just in case anybody was wondering.
댓글 수: 0
답변 (1개)
per isakson
2013년 12월 12일
편집: per isakson
2013년 12월 12일
A couple of thoughts:
Appended:
Try
%%my_timer_test
tmr = timer ...
( 'Name' , 'my_timer' ...
, 'TimerFcn' , @my_fcn ...
, 'BusyMode' , 'drop' ...
, 'ExecutionMode' , 'fixedRate' ...
, 'Period' , 6 ...
, 'StartDelay' , 1 ...
);
start( tmr )
where
function my_fcn( tmr, data )
filespec1 = 'my_fprintf_values.csv';
filespec2 = 'my_dlmwrite_values.csv';
new_value = randn(1); % stand-in for urlread( something )
fid = fopen( filespec1, 'a' );
fprintf( fid, '%f,%f\n', now, new_value );
fclose( fid );
M = [ now, new_value ]; % default precision not sufficient for now
dlmwrite( filespec2, M, '-append' )
end
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Web Services에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!