Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

use of msgbox in matlab

Asked by Locks

Locks (view profile)

on 11 Apr 2013

hi,

I tried to use the msgbox function in matlab, which I found here:

http://www.mathworks.ch/ch/help/matlab/ref/msgbox.html

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?

0 Comments

Locks

Locks (view profile)

Tags

Products

No products are associated with this question.

3 Answers

Answer by Image Analyst

Image Analyst (view profile)

on 11 Apr 2013
Edited by Image Analyst

Image Analyst (view profile)

on 11 Apr 2013
Accepted answer

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 Comment

Locks

Locks (view profile)

on 12 Apr 2013

thanks, that helps!

Image Analyst

Image Analyst (view profile)

Answer by per isakson

per isakson (view profile)

on 11 Apr 2013
Edited by per isakson

per isakson (view profile)

on 11 Apr 2013
    >> 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.

0 Comments

per isakson

per isakson (view profile)

Answer by Locks

Locks (view profile)

on 11 Apr 2013

What do I need to do if I would like to see which value the i has, which runs form 1 to 1000?

1 Comment

per isakson

per isakson (view profile)

on 11 Apr 2013

Se my answer above.

Locks

Locks (view profile)

Contact us