How to create pop out warning messages?
이전 댓글 표시
I am trying to create a function that will display messages by comparing a certain input. How can I display messages at each stage, which is like a warning box. Please help
function [ output_args ] = Newfunction( velocity )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
if (cond)
velocity >= 120;
h=msgbox('Your speed is okay');
else if velocity >=100 & velocity <=100;
h=msgboc('Warning:Approaching Stall');
else
h=msgbox('STALL');
end
end
답변 (3개)
Image Analyst
2013년 3월 6일
warningMessage = sprintf('Warning: your velocity = %f\nYou may stall!', velocity);
uiwait(warndlg(warningMessage));
The uiwait is in there so your code does not go blasting merrily along. The uiwait() will cause the code to pause until the user clicks OK.
Achchuthan Ganeshanathan
2013년 3월 6일
댓글 수: 9
Walter Roberson
2013년 3월 6일
Caution: 120<h<105 is interpeted as ((120<h)<105) which is ((0 or 1) < 105) which is always true. To test a range use (105 < h & h < 120)
Walter Roberson
2013년 3월 6일
We need to see how you are invoking Newfunction
Achchuthan Ganeshanathan
2013년 3월 6일
Image Analyst
2013년 3월 6일
You don't actually have the "then" word in there, do you? That's for Visual Basic, not MATLAB. Also, elseif is one word, not two.
Do you know how to use the debugger? If you did, you'd simply step into this code and see what the value of h is. Apparently it's nothing because you didn't pass anything it.
Walter Roberson
2013년 3월 6일
How are you starting the code running? Are you going to Newfunction in the editor and pressing F5 or selecting run from the menus? If you are, then you cannot do that when you want to pass in parameters. You need to instead go to the command line and give a command such as
Newfunction(108)
I recommend that you fix your "if" conditions as I described above. (Ask the interface here to expand comments)
Achchuthan Ganeshanathan
2013년 3월 8일
Image Analyst
2013년 3월 8일
You can put that function anywhere in the m-file. But don't do this:
if 105<h<120
do
if 105 < h && h < 120
Achchuthan Ganeshanathan
2013년 3월 8일
Walter Roberson
2013년 3월 8일
How are you starting the code running? Are you going to Newfunction in the editor and pressing F5 or selecting run from the menus? If you are, then you cannot do that when you want to pass in parameters. You need to instead go to the command line and give a command such as
Newfunction(108)
Notice that is at the command line, not part of your code. It would instruct MATLAB to actually run the code, passing in the value 108 for h. Change the 108 to the value you want to give to h for your run.
카테고리
도움말 센터 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!