What does Matlab do with blank values?

What does MATLAB do if a variable is left blank? Here's my situation. My program requests the user to input either "Yes" or "No" when asked a question. Using strcmp, if the answer is "Yes," I ask the user to input values for certain variables, which are used later in the program to test whether the solutions found are within certain ranges. In other words, I'm adding constraints to my solutions, but I only want the constraints if the user entered "Yes." The user can only input values for the variables mentioned above if (s)he enters yes-- but what if the answer is no? The variables will have no value assigned to them. Will MATLAB simply not evaluate the expressions that contain those variables? Or will it assign them an automatic value of zero? If the latter is true, I will need to add another layer of "if" statements, directing MATLAB whether to carry on with the constraints since a value of zero would still add constraints that I don't want.
I appreciate any help. If I'm not clear enough, I can post some code, although it's a bit long.

 채택된 답변

Sean de Wolski
Sean de Wolski 2011년 7월 6일

0 개 추천

[] is the empty set.
3*[]
[]*[]
[]+[2]
etc. to see how it behaves.
doc isempty
will be your friend.

댓글 수: 2

John  Smith
John Smith 2011년 7월 6일
So I should probably add an "&&" within the "if" statement which specifies my constraints, making sure it evaluates the constraint only when the input above was "Yes." Thanks!
Sean de Wolski
Sean de Wolski 2011년 7월 6일
You're welcome!
Yes, the && idea would work:
if (your_other_condition) && ~isempty(x) %not empty
do_stuff_with_x
else
do_not_do_stuff_with_x
end
You could also have default values that are only changed if they say yes.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

태그

Community Treasure Hunt

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

Start Hunting!

Translated by