MATLAB: Update TimerFcn each run

arrayMATLABtimertimerfcn

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

Best Answer

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.