functions in matlab gui
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Salaheddin Hosseinzadeh
2014-3-21
Your question is vague to me! I think U don't know how to pass variables from one GUI to the other one, is it so?! Unfortunately, I don't know it or at least can't remember! Do a favor, and clarify your question cuz I don't get anything!
采纳的回答
Jan
2014-3-21
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.
0 个评论
更多回答(2 个)
Salaheddin Hosseinzadeh
2014-3-21
@ 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!
Salaheddin Hosseinzadeh
2014-3-21
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 个评论
Salaheddin Hosseinzadeh
2014-3-21
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 ;)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Phased Array System Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!