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
채택된 답변
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
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
Jan
2021년 1월 28일
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에서 Downloads에 대해 자세히 알아보기
참고 항목
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)
