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.

 采纳的回答

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

2 个评论

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!
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