timer output saving in excel in new column

조회 수: 1 (최근 30일)
john white
john white 2021년 1월 27일
댓글: Walter Roberson 2021년 1월 28일
Hi
I write the code with timer function to do some calculate and I want to save the output in the excel file but I have 2 problems one is when it save the outputs it save them in the same column each time and delete older values and replace the new ones, the 2nd problem is at the function I don't know how to define the x to replace at the initial one which I have defined as zeros
this is my code:
function parentFunction
t=timer('Period',0.01,'ExecutionMode','fixedRate');
t.TimerFcn=@function1;
t.TasksToExecute=1000;
start(t)
function function1(~,~)
x=zeros(9,1);
k=5*x;
T=k+3;
xlswrite('Book100',T)
end
end
actually I want to save each T in new column, the excel file must be 9x1000 but it is just 9x1
and I want to update x each time to T just for the first time be zeros(9,1) the replaced with T for the other 999 times of TaskToExecute.
thanks

채택된 답변

Walter Roberson
Walter Roberson 2021년 1월 27일
Grab one of the File Exchange contributions that converts column numbers into excel notation; https://www.mathworks.com/matlabcentral/fileexchange?q=Excel+A1
Then
function function1(~,~)
persistent colnum
if isempty(colnum); colnum = 0; end
x=zeros(9,1);
k=5*x;
T=k+3;
colnum = colnum + 1;
excol = ConvertColumnNumberToExcel(colnum); %substitute the Fex contribution name here
xlswrite('Book100', T, [excol '1'])
end
  댓글 수: 12
john white
john white 2021년 1월 28일
any way , thanks a lot for your answers dear Walter
Walter Roberson
Walter Roberson 2021년 1월 28일
xlswrite('Book100', T, 1, [excol : excol])
will force it to write to sheet 1.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by