MATLAB Answers

functions in matlab gui

7 views (last 30 days)
Huseyin
Huseyin on 21 Mar 2014
Hi, I have created a function to use in GUI. The problem is that the function sometimes doesn't response to specific inputs and it gives an error on command window. This is normal and there is no problem until here. On GUI, I want to create a dialog box for this situation like 'Wrong Input'. I know the code for the dialog box, but I could'nt figure out how to add it. I think it should be like if that function doesnt work, answer will be zero and if it works the answer will be one. If I can create something like that it will be possible to add that dialog box when the function doesn't work. How can I do that?
Simply, how can I see the response of the function? (like 1 or 0) Thanks
  2 Comments
Huseyin
Huseyin on 21 Mar 2014
Ok let me explain it more clearly and simply. When the function works the output of the function is a matrix with the size [n,m] . When it didn't work, it gives me an error message on command window like 'Attempted to access mywork(0); index must be a positive integer or logical.' What I want to do is that if the function did not work properly, I want to see a dialog box (no error message on command window)

Sign in to comment.

Accepted Answer

Jan
Jan on 21 Mar 2014
It depends on what "the function does not respond" exactly means. If it stops with an error message, use try catch to catch the error and the corresponding message. If a specific output is replied, simply obtain this output, when you call the function from the callback of the GUI. Afterwards you can display the results how ever you want.
If is exactly the same situation, when you call a built-in function like e.g. sin(). When the input is a string, an error is thrown. When invalid input values are provided, e.g. NaN, NaN is replied also, such that you can catch this by checking the output.
Finally I assume, the actual question is not clear yet.

More Answers (2)

Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 21 Mar 2014
@ Husaiyn
Alright now it's clear!
Go to the error corresponding line, error line is probably given to you in the MATLAB error, or you may already know where is the error.
put it in a try catch
try
code
more code....
catch
diagbox('corresponding error');
end
and you won't see any error on the command window, instead you will see a dialogbox with a message and ...
I'm not sure if diagbox is the correct speling, check the MATLAB help plz, also for further options about dialog box.
Good Luck!
  1 Comment
Huseyin
Huseyin on 21 Mar 2014
Yes! It worked, thanks a lot!

Sign in to comment.


Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 21 Mar 2014
Actually, I think diagbox is for VC, I'm sure you already found it. but You may use this code
msgbox('Error Message','Name the msgbox','warn')
  2 Comments
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh on 21 Mar 2014
lol!
I'm sorry I'm still confused where I used diagbox or something very similar to diagbox, dialogbox or ...
It was either VC#, VC++, MATLAB! Or maybe none! I don't know.
Glad that your prob is solved ;)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!