フィルターのクリア

How to link message box OK button to other function? (matlab gui)

6 ビュー (過去 30 日間)
Abraham Chan
Abraham Chan 2015 年 4 月 6 日
コメント済み: Abraham Chan 2015 年 4 月 6 日
When user click 'OK', The ok button does something...
h = msgbox('Operation Completed','Success');
if strcmp(h,'OK')
..................
end
The strcmp not functioning.
What is the value of 'OK' in the msgbox?

回答 (1 件)

Stephen23
Stephen23 2015 年 4 月 6 日
編集済み: Stephen23 2015 年 4 月 6 日
When you read the documentation for msgbox, it clearly states the the output is "Message dialog box handle returned as a scalar". So the output is a handle, which is useful for keeping track of graphics objects, but it is certainly not a string. Who told you that the output was a string?
You can query the properties of the handle using get.
Also note that simply calling msgbox does not make MATLAB wait for a response, but the code will continue running as soon as the box has been created. If you wish to for the code execution to wait for the user response, then you will need to use waitfor.
You could try something like this:
waitfor(msgbox(...))
But it really depends on what functionality you want to achieve. Can you please describe what you want to happen with this code, and how it should respond given different user interactions (e.g. they close the dialog box without clicking okay).
  3 件のコメント
Stephen23
Stephen23 2015 年 4 月 6 日
When you read the documentation for questdlg it states clearly that it returns a string: "button is set to the name of the button pressed...", which is why this works for you.
Abraham Chan
Abraham Chan 2015 年 4 月 6 日
So how do i use msgbox the same way?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by