Fix an undefined variable in a nested if function?
显示 更早的评论
So here's a part of my code:
if ((destination_one > 0)&&(location_caller > 0))||((destination_one < 0)&&(location_caller < 0))
dc1 = abs(destination_one - location_caller);
elseif ((destination_one > 0)&&(location_caller < 0))||((destination_one < 0)&&(location_caller > 0))
dc1 = (abs(destination_one) + abs(location_caller));
end
if ((destination_two > 0)&&(location_caller > 0))||((destination_two < 0)&&(location_caller < 0))
dc2 = abs(destination_two - location_caller);
elseif ((destination_two > 0)&&(location_caller < 0))||((destination_two < 0)&&(location_caller > 0))
dc2 = (abs(destination_two) + abs(location_caller));
end
condition_4 = [(dc2 > dc1), (dc2 < dc1)];
check_condition_4 = sum(condition_4);
Whenever I try to run it against certain test cases, it will return an error saying that, for condition_4, dc2 is undefined. Is my end statement placement wrong? Thanks in advance.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Debugging and Improving Code 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!