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 件のコメント
john white
2021 年 1 月 27 日
thanks for your answer but it shows this error:
Undefined function 'ConvertColumnNumberToExcel' for input arguments of type 'double'.
Walter Roberson
2021 年 1 月 27 日
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?
Walter Roberson
2021 年 1 月 28 日
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
2021 年 1 月 28 日
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
- ...
Walter Roberson
2021 年 1 月 28 日
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
2021 年 1 月 28 日
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
Walter Roberson
2021 年 1 月 28 日
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
2021 年 1 月 28 日
thanks for answers , but it has the same result and makes 1000 sheets!
john white
2021 年 1 月 28 日
any way , thanks a lot for your answers dear Walter
Walter Roberson
2021 年 1 月 28 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
