timer output saving in excel in new column

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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 27 de En. de 2021
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 comentarios

john white
john white el 27 de En. de 2021
thanks for your answer but it shows this error:
Undefined function 'ConvertColumnNumberToExcel' for input arguments of type 'double'.
Walter Roberson
Walter Roberson el 27 de En. de 2021
I specifically commented to substitute the name of the Fex contribution you choose to use.
john white
john white el 28 de En. de 2021
Editada: john white el 28 de En. de 2021
sorry but I didn't understand what is your mean , what I must do ? replacing colnum in that line with what?
Walter Roberson
Walter Roberson el 28 de En. de 2021
Look in the File Exchange at the link I gave. Pick one of the contributions to work with. Install it, making sure that it is on your MATLAB path. Then change ConvertColumnNumberToExcel to the function name of the contribution.
Note: you can use the Add-on Explorer to add contributions.
john white
john white el 28 de En. de 2021
thanks but I didn't find the contribution with this purpose at this address
If you are using MATLAB Online, visit this URL https://www.mathworks.com/add-ons/1c54a094-2b81-46f5-96b9-2f2ac14fc531/ and click on Add .
If not, then visit https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/1c54a094-2b81-46f5-96b9-2f2ac14fc531/017d7cbf-a0c8-4dec-94e9-3c2c71723196/packages/zip and save the file to your downloads directory, and then in MATLAB use the folder view to visit the downloads directory and double-click on the mltbx file to run it in MATLAB, and that will install the program.
Once that all is done, 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 = ExcelColumn(colnum);
xlswrite('Book100', T, [excol '1'])
end
This was, by the way, the very first contribution in that list of contributions I had you visit.
john white
john white el 28 de En. de 2021
ok thanks you're right , sorry I have searched the ConvertColumnNumberToExcel
I downloaded the ExcelColumn package but this code replaces the values in new sheet, for example in my code this order makes 1000 sheets in the excel file and replaces the T(1:9) in the first 9 rows, but I want to replace the new T in the new column in the same sheet and make a sheet with 9x1000 cells
function function1(~,~)
persistent colnum
if isempty(colnum); colnum = 0; end
x=zeros(9,1);
k=5*x;
T=k+3;
colnum = colnum + 1;
excol = ExcelColumn(colnum);
xlswrite('Book100', T, [excol : excol])
end
john white
john white el 28 de En. de 2021
thanks for answers , but it has the same result and makes 1000 sheets!
john white
john white el 28 de En. de 2021
any way , thanks a lot for your answers dear Walter
xlswrite('Book100', T, 1, [excol : excol])
will force it to write to sheet 1.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Preguntada:

el 27 de En. de 2021

Comentada:

el 28 de En. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by