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

 Akzeptierte Antwort

Jan
Jan am 31 Jan. 2013

1 Stimme

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 Kommentar

Hugo
Hugo am 12 Feb. 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]

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Language Fundamentals finden Sie in Hilfe-Center und File Exchange

Produkte

Gefragt:

am 31 Jan. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by