use of msgbox in matlab

9 ビュー (過去 30 日間)
Locks
Locks 2013 年 4 月 11 日
hi,
I tried to use the msgbox function in matlab, which I found here:
I tried to take the formula to display at which i we are currrently with the code:
h = msgbox(i)
unfortunately it's not working at all. From VBA I know that it's just necessary to enter msgbox and the variable, but that doesn't work either
what do I need t change?

採用された回答

Image Analyst
Image Analyst 2013 年 4 月 11 日
編集済み: Image Analyst 2013 年 4 月 11 日
You need to pass it a string
for k = 1 : 10
message = sprintf('k = %4d\n', k);
uiwait(msgbox(message));
% You can use fprintf() instead if you don't want to prompt the user.
fprintf(message); % Goes to command window.
end
Or better yet, use questdlg() so the user can have an opportunity to break out of your 1000 iteration loop:
for k = 1 : 10
message = sprintf('k = %4d\nContinue?', k);
reply = questdlg(message, 'Continue', 'OK', 'Cancel', 'OK');
if strcmpi(reply, 'Cancel')
% User said Cancel, so exit.
break;
end
end
I used k as a loop variable because you're not supposed to use i or j - they're the imaginary variable.
  1 件のコメント
Locks
Locks 2013 年 4 月 12 日
thanks, that helps!

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

その他の回答 (2 件)

per isakson
per isakson 2013 年 4 月 11 日
編集済み: per isakson 2013 年 4 月 11 日
>> h = msgbox('This is my message')
h =
0.0012
>>
works fine here. Message should be a string.
[Added:] To show the value of the numeric variable: i
h = msgbox( num2str( i ) )
VB do things more automagically than Matlab. Here you need to do the conversion explicitely.

Locks
Locks 2013 年 4 月 11 日
What do I need to do if I would like to see which value the i has, which runs form 1 to 1000?
  1 件のコメント
per isakson
per isakson 2013 年 4 月 11 日
Se my answer above.

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

カテゴリ

Help Center および File ExchangeScope Variables and Generate Names についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by