wait bar in MATLAB gui in nested FOR loop
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
I have to show a progress bar in matlab guide that appears while running FOR loop and shows progress for each iteration. Moreover, the user should not be able to close it until the calculation stops, so as to prevent the user from making any changes. Example code is as follows
MBTs = minMBT:stepMBT:maxMBT;
MATs = minMAT:stepMAT:maxMAT;
i=1;
for MAT = MATs
j = 1;
for MBT = MBTs
%some calculations
j = j + 1;
end
i = i + 1;
end
채택된 답변
MBTs = minMBT:stepMBT:maxMBT;
MATs = minMAT:stepMAT:maxMAT;
n = length(MATs) * length(MBTs);
c = 0;
H = waitbar(0, 'Please wait...');
for i1 = 1:length(MATs)
MAT = MATs(i1);
for i2 = 1:length(MBTs)
MBT = MBTs(i2);
%some calculations
% Update the waitar:
if ~ishghandle(H)
error('User closed waitbar.');
end
c = c + 1;
waitbar(c / n, H, sprintf('%d of %d', c, n));
end
end
It would be brute to forbid, that the user closes the waitbar. Imagine that the loop runs for 2 hours for unknown reasons. Do you really block a premature stopping? User hate such restrictions for good reasons.
댓글 수: 9
Aash
2018년 5월 11일
thanks Jan for such a detailed answer. I actually want to disable the cancel function so that no changes can be made by the user during the execution otherwise it will become mess
Aash
2018년 5월 11일
There is one more thing that I want to change the arrow cursor to hour watch (loading cursor) and it should change back to the arrow curser after loof stops.
What does "disable the cancel function" mean? Which cancel function? If you do not specify the 'CreateCancelBtn' property of waitbar, there is no Cancel button.
H = waitbar(0, 'Please wait...');
WindowAPI(H, 'Button', 'off');
I've showed in my code how to catch a closed waitbar window. You should be able to start a proper cleanup instead of the error.
To change the cursor:
H = waitbar(0, 'Please wait...');
set(H, 'Pointer', 'watch');
...
set(H, 'Pointer', 'arrow');
Aash
2018년 5월 12일
I have tried doing this for cursor but it only changes cursor shape on the window where the waitbar is showing, What if I want to chnage it on entire GUI?
Jan
2018년 5월 12일
What is "the entire GUI"? Matlab's command window or the operating system? You can set the cursor in each window by using its handle. So if you have e.g. a figure created by GUIDE, use its handle for the above commands.
Aash
2018년 5월 12일
I mean Matlabs uipanel where the buttons are present. I am attaching the figure the cursor is curently chnaging when i put it on waitbar not the window below it
So you mean the window called "Untitled"? It seems to be created by GUIDE. And I guess, that the waitbar is opened inside one of the callbacks? Then insert there:
FigH = ancestor(hObject, 'figure');
set(FigH, 'Pointer', 'watch');
...
set(FigH, 'Pointer', 'arrow');
You have the figure handle inside the struct handles also, but I'm not sure, how it is called. You can check this by your own: Set a breakpoint in the code and display the contents of the handles struct.
Aash
2018년 5월 12일
Thank you so much for the help Jan.
Jan
2018년 5월 12일
You are welcome, Aash.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
태그
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
