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
Jan
2018 年 5 月 12 日
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 についてさらに検索
タグ
参考
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)
