Update TimerFcn each run

I am trying to simulate a controller and its I/O inputs. I want to read data from an Excel file every 5 minutes (with Timer function) and then store each new point in an array modifying the index accordingly (in this case n). The 2 codes are shown below. I would like to include something similar as set(t, 'TimerFcn',{[@calling] [n+1]}) at the end of the calling function, but the t timer is not recognized from the calling function. The code I show here reads only the first row, and every 5 minutes it changes the array in the proper index, but since the calling fucntion is set at "1" it is always reading the first row. Any help would be appreaciated.
t = timer('StartDelay', 2, 'Period', 300,...
'ExecutionMode', 'fixedRate');
n=1;
power=zeros(1,10);
t.TimerFcn = { @calling,t.TimerFcn,n};
start(t)
c=calling(~, ~,n)
[Num_Resources,Text_Resources,Raw_Resources] = xlsread('Resources2011.xlsx','2011',['E' num2str(n) ':G' num2str(n)]);
evalin('base',['power(n-1)=' num2str(Num_Resources(1))]);
assignin('base','n',n+1);

 채택된 답변

Jan
Jan 2013년 1월 31일

1 개 추천

Do not use the function call of the timer function to carry important varying data, but the Timer's UserData.
n = 1;
t = timer(..., 'UserData', n);
...
n = n + 1;
set(t, 'UserData', n);
I cannot understand the relation between your text and the posted code. Seeing the function calling() might be helpful to understand, what you are doing. It is not clear why you assign n in the base workspace and which effects this should have.

댓글 수: 1

Hugo
Hugo 2013년 2월 12일
Thank you for your input. At the end the problem was solved by calling the method itself. The calling function should be: function calling(obj, event,n). The n is a counter to increase the size in every step. The example of what I did is (if someone else is interested is): @t=0s x=[12] @t=300s x=[12,14] @t=600 x=[12,14,13]

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

질문:

2013년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by