display intermediate results while the code is running
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi, I have a code that takes very long time to run (more than 2 days). I want to display intermediate results while the code is running without pausing the code as this will delay the code further. I am not sure how to do this. Please let me know if you have any suggestion. Output can be in the form of .mat/excel/csv.
採用された回答
Image Analyst
2018 年 3 月 26 日
Lots of ways. For example, you could use fprintf() to print out info to the command window. Or you could do something with a GUI, such as a standalone/floating waitbar/progress bar. Or you could, like I do when I have processing that takes more than about 15 minutes, have a progress bar right on your GUI. Or in your gui, you could just update the gui, like show text that says "Now processing file 1452 of 123487...", etc. What is your preference?
7 件のコメント
Isha Sharma
2018 年 3 月 26 日
Thank you for your reply. I prefer fprint(). So, what I have is one outer loop that runs for like 1000 iterations and there are two inner loops that run for 200 iterations. I want to display results of outerloop and inner loop. For example when outerloop = 1, what are the values of variables in inner loops 1 and 2.
There is no fprint() but there is an fprintf(). You can do
for k1 = 1 : 1000
fprintf('Now processing iteration #%d...\n', k1);
fprintf('About to start inner loop 1.\n');
for k2 = 1 : 200
fprintf('Beginning first inner loop iteration %d of %d.\n', k2, 200);
% code
end
fprintf('About to start inner loop 2.\n');
for k3 = 1 : 200
fprintf('Beginning second inner loop iteration %d of %d.\n', k3, 200);
% code
end
fprintf('Done with both inner loops in iteration #%d.\n', k1);
end
Isha Sharma
2018 年 3 月 26 日
編集済み: Image Analyst
2018 年 3 月 26 日
I am using fprintf() to write my output:
fprintf(fileID1, '%5d %5d %5d %5d %5d\n', k1, k2, history_f.time(k2), rho, a_det ) ;
The issue is when I go to next iteration, the next set of results are getting displayed in the same row. They do not go to the next line. I am not sure what is the issue here, could you please help.
It looks like they're going to a file so you won't see the printout "live". To go to the command window, don't use fileID1 or else use the number 1 instead of fileID1.
If you really want it to go to a file, the most likely problem is the program you're opening it up with, like notepad or wordpad. The first thing to try is to make sure you're opening the file with the 'wt' option, not the 'w' option:
fileID1 = fopen(outputFileName, 'wt');
That should probably work. If that doesn't work, then try writing \n\r or \r\n instead of just \n.
'wt' option works and results are recorded in the next row :).
However, results are not displayed while the code is running especially for k2 loop (ADMM_Release.txt). When I stop the code (Ctrl+C) then I can see results in text file. Not sure whats going on? This is what I have:
fileID1 = fopen('ADMM_Release.txt','wt');
fileID = fopen('ADMM_Fix.txt','wt');
for k1 = 1:1000
for k2 = 1:200
fprintf(fileID1, '%5d %5d %5d %5d %5d\n', k1, k2, time_Release_MIQP, rho, a_det ) ;
end
for k3 = 1:200
fprintf(fileID, '%5d %5d %5d %5d %5d\n', k1, k3, history_f.objval{k3}, time_Fix_LP, rho );
end
end
sorry this is the correct version
for k1 = 1:1000
for k2 = 1:200
fprintf(fileID1, '%5d %5d %5d %5d %5d\n', k1, k2, time_Release_MIQP, rho, a_det ) ;
end
for k3 = 1:200
fprintf(fileID, '%5d %5d %5d %5d %5d\n', k1, k3, history_f.objval{k3}, time_Fix_LP, rho );
end
end
fclose(fileID);
fclose(fileID1);
Isha Sharma
2018 年 3 月 26 日
it is working now. Thanks you!
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Low-Level File I/O についてさらに検索
タグ
参考
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)
