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);

 Respuesta aceptada

Jan
Jan el 31 de En. de 2013

1 voto

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 comentario

Hugo
Hugo el 12 de Feb. de 2013
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]

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Language Fundamentals en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 31 de En. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by