importing files automatically callback function error
조회 수: 6 (최근 30일)
이전 댓글 표시
function importfcn
% wait an extra second to ensure that the file modification is complete
pause(1.0);
% read the data from file
fileToRead = fullfile('C:\Users\wolfgang\Desktop\file1.csv');
circa = xlsread(fileToRead);
kevin=0.5*(circa(:,4)+circa(:,5)).'
assignin('base','kevin',kevin)
% do something with the data
end
fsw = System.IO.FileSystemWatcher();
fsw.Path = 'C:\Users\wolfgang\Desktop';
fsw.Filter = 'file.csv';
fsw.EnableRaisingEvents = true;
listenerhandle = addlistener(fsw, 'Changed', @importfcn);
%signature of importfcn is function importfcn(sender, eventargs)
%add a small delay in importfcn before reading the file as the event is raised
%to make sure that file modification is complete
Then I get the following error: Warning: Error occurred while executing callback: Error using importfcn Too many input arguments.
Warning: Error occurred while executing callback: Error using importfcn Too many input arguments.
When I type in importfcn then everything is ok and the file gets imported as variable kevin.
댓글 수: 0
채택된 답변
Sean de Wolski
2014년 12월 10일
addlistener automatically passes along two inputs, source and eventdata.
You can either have your function ignore these or ignore them in the call to addlistener
@(~,~)importfcn
The two ~s deny both inputs and then call importfcn as is.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!