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
采纳的回答
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 个评论
thanks for your answer but it shows this error:
Undefined function 'ConvertColumnNumberToExcel' for input arguments of type 'double'.
I specifically commented to substitute the name of the Fex contribution you choose to use.
john white
2021-1-28
编辑:john white
2021-1-28
sorry but I didn't understand what is your mean , what I must do ? replacing colnum in that line with what?
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.
thanks but I didn't find the contribution with this purpose at this address
Your search find a working function as first hit, and a lot of others:
- https://www.mathworks.com/matlabcentral/fileexchange/30180-calculate-excel-range
- https://www.mathworks.com/matlabcentral/fileexchange/28794-convert-index-to-excel-a1-notation
- https://www.mathworks.com/matlabcentral/fileexchange/81258-getletter
- https://www.mathworks.com/matlabcentral/fileexchange/28343-column-converter-for-excel
- https://www.mathworks.com/matlabcentral/fileexchange/14008-convert-an-a1-style-spreadsheet-column-label-to-a-number
- https://www.mathworks.com/matlabcentral/fileexchange/15748-excel-column-number-to-column-name
- ...
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.
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
thanks for answers , but it has the same result and makes 1000 sheets!
any way , thanks a lot for your answers dear Walter
xlswrite('Book100', T, 1, [excol : excol])
will force it to write to sheet 1.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Spreadsheets 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
