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
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);
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
